1 <%@ WebHandler Language="C#" Class="MakeImg" %> 2 3 using System; 4 using System.Web; 5 using System.Drawing; 6 7 public class MakeImg : IHttpHandler { 8 9 public void ProcessRequest (HttpContext context) { 10 context.Response.ContentType = "image/jpg";//告诉浏览器以什么编码方式处理2进制流 11 string imgPath="upload\1.jpg"; 12 using (Image img = Bitmap.FromFile(context.Server.MapPath(imgPath)))//找到图片文件的物理路径 13 { 14 using(Graphics g=Graphics.FromImage(img)) 15 { 16 g.DrawString("大英哥",new Font("黑体",16),Brushes.Black,0,0); 17 img.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg); 18 } 19 } 20 21 } 22 23 public bool IsReusable { 24 get { 25 return false; 26 } 27 } 28 29 }