using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
namespace TestHandler
{
public class NumberBackGround : IHttpHandler
{
public bool IsReusable
{
get
{
return false;
}
}
public void Proce***equest(HttpContext context)
{
//获取物理路径
string path = context.Request.PhysicalPath;
//获取水印路径
string logo = context.Server.MapPath("~/p_w_picpaths/logo.jpg");
Image img = Image.FromFile(path);
Graphics g = Graphics.FromImage(img);
//喷logo
Image imgLogo = Image.FromFile(logo);
float x=(float)(img.Width-1000);
float y = (float)(img.Height -200);
g.DrawImage(imgLogo,new RectangleF(x,y,1000f,200f));
//处理后场景以图片形式在客户端响应
img.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
img.Dispose();
imgLogo.Dispose();
}
}
web.config配置
在<system.web>节点下面添加
<httpHandlers>
<add verb="*" path="p_w_picpaths/*.jpg" type="NumberBackGround"/>
</httpHandlers>
|
转载于:https://blog.51cto.com/flykai/749604