//在App_code下建一个类
using System;
using System.Web;
using System.Drawing;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
Image img=Image.FromFile((context.Request.PhysicalPath));
Graphics g=Graphics.FromImage(img);
Font font=new Font("楷体",10);
g.DrawString("I love you", font, Brushes.Red, new PointF(1, 1));
context.Response.ContentType = "image/jpeg";
img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
}
//在config下配置
<httpHandlers>
<add verb="*" path="img/*.jpg" type="方法名"/>
</httpHandlers>