首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

ASP.NET 餅圖繪製核心:GraphicsPath 路徑建構、位圖產生與 HTML 字串輸出 (第 8 講第 7 部分)

     編輯:關於C語言

Draw 繪製方法

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);
    }
}

CreateBitmap 產生位圖 (供圖片服務頁面)

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;
}

CreatePath 建構扇形路徑

public GraphicsPath CreatePath(PieShapeItem item)
{
    GraphicsPath path = new GraphicsPath();
    path.AddPie(intLeft, intTop, intWidth, intHeight, item.StartAngle, item.EndAngle - item.StartAngle);
    return path;
}

GetHtmlString 概覽

參考第 8 部分 (ID 81285) 完整實作:產生 img + map + area shape=poly HTML 字串。

關鍵技術點

  • GraphicsPath.AddPie 直接建立扇形路徑,支援填充與描邊。
  • TranslateTransform 將繪圖原點移至餅圖左上角,簡化座標計算。
  • SmoothingMode.HighQuality 開啟反鋸齒。
  • 位圖建立於記憶體,無需寫入暫存檔,適合 Web 伺服器環境。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved