[C#]如何利用 GDI+ 進行繪製並存檔
發表於 : 2008年 11月 26日, 03:20
使用 Bitmap 進行, 配合 Graphics 的 FromImage 來取得繪製的控制, 之後再進行存檔, 指定格式即可!
附件為輸出的結果!!
代碼: 選擇全部
private void button1_Click(object sender, System.EventArgs e)
{
Bitmap bmp = new Bitmap(100, 100);
Graphics g = Graphics.FromImage(bmp);
Pen p = new System.Drawing.Pen(System.Drawing.Color.Red);
g.DrawLine(p, 10, 10, 20, 20);
Font drawFont = new Font("Arial", 9);
SolidBrush drawBrush = new SolidBrush(Color.Blue);
g.DrawString("test string", drawFont, drawBrush, 10, 40);
bmp.Save("c:\1.bmp", System.Drawing.Imaging.Imageformat.Bmp);
}