[C#]GDI畫出文字與圖片合成PNG檔案
//設定字型與字體大小
System.Drawing.Font drawFont = new System.Drawing.Font("標楷體", size);//設定粗體
System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
//設定為字串格式
System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();
public void TandPtoOne(String Imgpath01, String Imgpath02, String text01, String text02, String Sdate, int x1, int x2, int x3, int y, int y1, int size)
{
System.Drawing.Font drawFont = new System.Drawing.Font("標楷體", size);
System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();
System.Drawing.Font drawFont01 = new System.Drawing.Font("標楷體", 8);
string sourcePath = Imgpath01;
Image souceImage = Image.FromFile(sourcePath);
Image zoomImage = new Bitmap(souceImage.Width, souceImage.Height) as Image;
Graphics graphics0 = Graphics.FromImage(zoomImage);
graphics0.DrawImage(souceImage, 0, 0, souceImage.Width, souceImage.Height);
graphics0.DrawString(text01, drawFont, drawBrush, x1, y, drawFormat);
graphics0.DrawString(text02, drawFont, drawBrush, x2, y, drawFormat);
graphics0.DrawString(Sdate, drawFont01, drawBrush, x3, y1, drawFormat);
zoomImage.Save(Imgpath02);
// label1.Text = souceImage.Width + " " + souceImage.Height;
drawFont.Dispose();
drawBrush.Dispose();
}
留言