问题描述
大家有没有ASP.NET上传图片给图片加水印例子没有啊?在网上没找到呢?有例子可以给我发一个嘛谢谢。273752751@qq.com
解决方案
解决方案二:
usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.IO;usingSystem.Drawing;usingSystem.Drawing.Imaging;///<summary>///PictureHandler的摘要说明///</summary>publicclassPicHandler:IHttpHandler{publicvoidProcessRequest(HttpContextcontext){context.Response.ContentType="text/plain";stringimgUrl=context.Request.PhysicalPath;//得到当前处理图片的物理路径if(File.Exists(imgUrl)){Imageimg=Image.FromFile(imgUrl);//通过图片路径得到图片对象Imagewatering=Image.FromFile(context.Server.MapPath("~/themes/images/water.jpg"));//得到数字水印图片Graphicsg=Graphics.FromImage(img);//通过图片对象创建画布g.DrawImage(watering,newRectangle(img.Width-watering.Width,img.Height-watering.Height,watering.Width,watering.Height),0,0,watering.Width,watering.Height,GraphicsUnit.Pixel);//画图context.Response.ContentType="image/jpeg";//设置图片的格式img.Save(context.Response.OutputStream,ImageFormat.Jpeg);//把图片保存在输出流中g.Dispose();//销毁画布img.Dispose();//销毁图片context.Response.End();}else{Imagedefaultimg=Image.FromFile(context.Server.MapPath("~/themes/images/water.jpg"));//通过图片路径得到默认图片对象Imagewatering=Image.FromFile(context.Server.MapPath("~/themes/images/water.jpg"));//得到数字水印图片Graphicsg=Graphics.FromImage(defaultimg);//通过图片对象创建画布g.DrawImage(watering,newRectangle(defaultimg.Width-watering.Width,defaultimg.Height-watering.Height,watering.Width,watering.Height),0,0,watering.Width,watering.Height,GraphicsUnit.Pixel);//画图context.Response.ContentType="image/jpeg";//设置图片的格式defaultimg.Save(context.Response.OutputStream,ImageFormat.Jpeg);g.Dispose();defaultimg.Dispose();context.Response.End();}}publicboolIsReusable{get{returnfalse;}}}
解决方案三:
引用1楼fengyarongaa的回复:
C#codeusingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls.WebParts;usingSystem.……
+1
解决方案四:
该回复于2012-01-15 10:04:52被版主删除
解决方案五:
解决方案六:
百度google有很多啊。楼主懒了。