public void Draw(Graphics g, Rectangle clipRect)
{
foreach (PieShapeItem item in this)
using (GraphicsPath path = CreatePath(item))
using (SolidBrush b = new SolidBrush(item.Color))
{
g.FillPath(b, path);
g.DrawPath(Pens.Black, path);
}
}
public Bitmap CreateBitmap()
{
Bitmap bmp = new Bitmap(intWidth + 1, intHeight + 1);
using (Graphics g = Graphics.FromImage(bmp))
{
g.Clear(Color.White);
g.TranslateTransform(intLeft, intTop);
g.SmoothingMode = SmoothingMode.HighQuality;
Draw(g, Bounds);
}
return bmp;
}
public GraphicsPath CreatePath(PieShapeItem item)
{
GraphicsPath path = new GraphicsPath();
path.AddPie(intLeft, intTop, intWidth, intHeight, item.StartAngle, item.EndAngle - item.StartAngle);
return path;
}
參考第 8 部分 (ID 81285) 完整實作:產生 img + map + area shape=poly HTML 字串。
GraphicsPath.AddPie 直接建立扇形路徑,支援填充與描邊。TranslateTransform 將繪圖原點移至餅圖左上角,簡化座標計算。SmoothingMode.HighQuality 開啟反鋸齒。