一个在图片上写字的方法

来源:互联网 发布:淘宝开店自动充值 编辑:程序博客网 时间:2024/04/29 15:16
Code:
  1. string url = @"F:/123.jpg";   
  2.      String src = url;   
  3.      String dest = @"F:/xx.jpg";   
  4.      int thWidth = 624;//生成缩略图的大小   
  5.      int thHeight = 306;   
  6.      System.Drawing.Image img = System.Drawing.Image.FromFile(url);//image对象装载源图像   
  7.      int srcWidth = img.Width;   
  8.      int srcHeight = img.Height;   
  9.      Bitmap bmp = new Bitmap(thWidth,thHeight);   
  10.      System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp);   
  11.      gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;   
  12.      gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;   
  13.      gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;   
  14.   
  15.      System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0,0,thWidth,thHeight);   
  16.      gr.DrawImage(img,rectDestination,0,0,srcWidth,srcHeight,GraphicsUnit.Pixel);   
  17.      SolidBrush drawBrush = new SolidBrush(Color.Red);   
  18.      Font drawFont = new Font("宋体",10,FontStyle.Bold,GraphicsUnit.Millimeter);   
  19.      int xPos=img.Height-(img.Height-25);   
  20.      int yPos = 3;   
  21.      gr.DrawString("你好!",drawFont,drawBrush,xPos,yPos);   
  22.      bmp.Save(dest);   
  23.      bmp.Dispose();   
  24.      img.Dispose();  

 

原创粉丝点击