当前位置: 编程技术>.net/c#/asp.net
c#通过httphandler添加水印的代码
来源: 互联网 发布时间:2014-08-30
本文导语: 示例代码: 代码示例: HttpRequest request = context.Request; HttpServerUtility server = context.Server; string Water =server.MapPath("~/vener.png"); HttpResponse response = context.Response; string s = request.PhysicalPath; response.ContentType = "Images/jpeg"; if (Fi...
示例代码:
代码示例:
HttpRequest request = context.Request;
HttpServerUtility server = context.Server;
string Water =server.MapPath("~/vener.png");
HttpResponse response = context.Response;
string s = request.PhysicalPath;
response.ContentType = "Images/jpeg";
if (File.Exists(s) && request.UrlReferrer!=null&& request.UrlReferrer.ToString() == "http://localhost/")
{
Image image = Image.FromFile(s);
Image wimage =Image.FromFile(Water);
Graphics gs = Graphics.FromImage(image);
gs.DrawImage(wimage,new Rectangle(image.Width-wimage.Width,image.Height-wimage.Height,wimage.Width,wimage.Height));
gs.Dispose();
image.Save(response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
else
{
Image image = Image.FromFile(Water);
image.Save(response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
image.Dispose();
}
HttpServerUtility server = context.Server;
string Water =server.MapPath("~/vener.png");
HttpResponse response = context.Response;
string s = request.PhysicalPath;
response.ContentType = "Images/jpeg";
if (File.Exists(s) && request.UrlReferrer!=null&& request.UrlReferrer.ToString() == "http://localhost/")
{
Image image = Image.FromFile(s);
Image wimage =Image.FromFile(Water);
Graphics gs = Graphics.FromImage(image);
gs.DrawImage(wimage,new Rectangle(image.Width-wimage.Width,image.Height-wimage.Height,wimage.Width,wimage.Height));
gs.Dispose();
image.Save(response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
else
{
Image image = Image.FromFile(Water);
image.Save(response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
image.Dispose();
}
webconfig配置文件
代码示例: