读本地图像文件,在上面写一些文件,再传到WWW服务器上

 

  1   public class ImgExtends
  2 
  3     {
  4 
  5         /// <summary>
  6 
  7         /// 像本地图像文件上写字,并上传本地服务器
  8 
  9         /// </summary>
 10 
 11         /// <param name="imgserverurl">Web服务器上的图片路径</param>
 12 
 13         /// <param name="title">图片上的文字</param>
 14 
 15         /// <returns></returns>
 16 
 17         public static string GetImg(string imgserverurl, string title)
 18 
 19         {
 20 
 21             try
 22 
 23             {
 24 
 25                 if (!string.IsNullOrEmpty(imgserverurl))
 26 
 27                 {
 28 
 29                     string Path = System.Web.HttpContext.Current.Server.MapPath("/Upload/Product");
 30 
 31                     string FileName = "\\" + VCommons.Utils.GetNewGuid() + ".jpg";
 32 
 33  
 34 
 35                     Image img = Image.FromFile(imgserverurl);
 36 
 37                     int width = img.Width;
 38 
 39                     int height = img.Height;
 40 
 41  
 42 
 43                     Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
 44 
 45                     bitmap.SetResolution(img.HorizontalResolution, img.VerticalResolution);
 46 
 47  
 48 
 49                     Graphics grap = Graphics.FromImage(bitmap);
 50 
 51                     grap.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
 52 
 53                     grap.DrawImage(img, new Rectangle(0, 0, width, height), 0, 0, width, height, GraphicsUnit.Pixel);
 54 
 55  
 56 
 57                     Font font = new Font("微软雅黑", 24, FontStyle.Bold);
 58 
 59  
 60 
 61                     SolidBrush solid = new SolidBrush(Color.Turquoise);
 62 
 63  
 64 
 65                     StringFormat format = new StringFormat();
 66 
 67                     format.Alignment = StringAlignment.Near;
 68 
 69                     grap.DrawString(title, font, solid, 25, 18, format);
 70 
 71                     grap.Dispose();
 72 
 73  
 74 
 75                     bitmap.Save(Path + FileName, ImageFormat.Jpeg);
 76 
 77                     return "http://" + RequestHelper.GetHost() + "/Upload/Product" + FileName;
 78 
 79                 }
 80 
 81                 else
 82 
 83                 {
 84 
 85                     return string.Empty;
 86 
 87                 }
 88 
 89  
 90 
 91             }
 92 
 93             catch (Exception)
 94 
 95             {
 96 
 97                 return string.Empty;
 98 
 99             }
100 
101         }
102 
103     }

 

posted @ 2011-06-28 14:51  张占岭  阅读(407)  评论(0编辑  收藏  举报