<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Drawing;
using System.IO;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Request.ContentType = "IMAGE/JPEG";
//原始图片的路径,并转换为物理路径
string path = context.Request.MapPath("~/images/0 (8).jpg");
//原始图片实例
Image img= Image.FromFile(path);
//需要加的水印图片
Image waterImg = Image.FromFile(context.Request.MapPath("~/images/1 (8).gif"));
//画布
Graphics g = Graphics.FromImage(img);
SolidBrush sb = new SolidBrush(Color.Red);
Font f = new Font("宋体",14);
//在图片上绘制水印
g.DrawImage(waterImg,img.Width-waterImg.Width,img.Height -waterImg.Height);
//显示
img.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
waterImg.Dispose();
}
public bool IsReusable {
get {
return false;
}
}
}