日期:2014-05-18  浏览次数:20335 次

图片加水印
hotelPicPath += filename;
  hotelPicPath = Server.MapPath(hotelPicPath);
  HotelPhoto.SaveAs(hotelPicPath);
  //hotelInfo.PicUrl = filename;
  //加文字水印
  //System.Drawing.Image image = System.Drawing.Image.FromFile(hotelPicPath);
  //System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
  //g.DrawImage(image,0,0,image.Width,image.Height);
  //System.Drawing.Font f = new System.Drawing.Font("Verdana",20);
  //System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
  //string addText = "华润广告";
   
  //g.DrawString(addText,f,b,10,10);
  //g.Dispose();
  //加图片水印
  System.Drawing.Image image = System.Drawing.Image.FromFile(hotelPicPath);
  string copyPath=@"../Hotel_Admin/Hotel_Images/huarun.jpg";
  System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Server.MapPath(copyPath));
  Graphics g = Graphics.FromImage(image);
  g.DrawImage(copyImage, new Rectangle(image.Width - copyImage.Width, image.Height - copyImage.Height, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
  //string newPath = @"../Hotel_Admin/Hotel_Images/" + "_new" + filename;
  hotelInfo.PicUrl = "_new" + filename; 
  g.Dispose();
  //MemoryStream ms = new MemoryStream();
  string newPath = Server.MapPath(".")+"/Hotel_Images/"+ "_new" + filename;
   
  //string savePath = @newPath;
   
  image.Save(newPath);
  image.Dispose(); 
  怎么老提示 GDI+ 中发生一般性错误。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.Runtime.InteropServices.ExternalException: GDI+ 中发生一般性错误。
   


------解决方案--------------------
image.Save(newPath,ImageFormat.Jpeg);一般这个错误是无法生成png等图片格式导致的。
手工写的,最后一个参数不确定是不是写对了。
------解决方案--------------------
以前看到此类错误,好像是不能保存当前使用的img,需要重新定义一个img,将前一个赋值给后一个,csdn里面有此类贴。

------解决方案--------------------
看看这里:

http://hi.baidu.com/tease/blog/item/c52b58da2aad2edbb7fd4831.html