string mapho = request["imgpath"];//获取某个页面传过的图片名称
string str1 = Server.MapPath(mapho);//要添加水印的图片
string str2 = Server.MapPath("WaterMark.jpg");//添加的内容图片
System.Drawing.Image bmp = System.Drawing.Image.FromFile(str1);
Graphics gs = Graphics.FromImage(bmp);
System.Drawing.Image bmp2 = System.Drawing.Image.FromFile(str2);
//两张图片合并
gs.DrawImage(bmp2, bmp.Width-bmp2.Width, bmp.Height - bmp2.Height, bmp2.Width, bmp2.Height);
Response.ContentType = "image/jpeg";//输出类型
bmp.Save(Response.OutputStream,ImageFormat.Jpeg);//保存
用法:
新建一个页面在页面加载事件里添加以上代码。
在要用这个图片的时候把它的图片URL地址等于这个页面就可以了.
例如:<asp:image runat="server" ImageUrl="以上页面的名称.aspx?imgpath="+"图片名称"></asp:image>