图片印字(C#)

来源:互联网 发布:发饰品牌 知乎 编辑:程序博客网 时间:2024/05/01 10:27

//img.Text为存放着图片路径的TextBox

//word.Text为存放要在图片上打印的文字的TextBox


private void button9_Click(object sender, System.EventArgs e)
  {
   Bitmap sourceImg=new Bitmap(@img.Text);
   Graphics g=Graphics.FromImage((Image)sourceImg);
   //SolidBrush brush=new SolidBrush(Color.Red);
   Font drawFont = new Font("Arial", 20, FontStyle.Regular, GraphicsUnit.Point);
   int xPos =25;
   int yPos = 3;
   string savePath=img.Text.Substring(0,img.Text.Length-4)+"XX.jpg";
   g.DrawString (word.Text, drawFont, Brushes.Blue, xPos, yPos);
   sourceImg.Save(@savePath,System.Drawing.Imaging.ImageFormat.Jpeg);
   sourceImg=null;
   MessageBox.Show("文字打印成功!");
  }

原创粉丝点击