handler

<%@ WebHandler Language="C#" class="Handler" %>

using System;
using System.Web;
using System.IO;
using System.Drawing;

public class Handler : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {
        string path = System.Configuration.ConfigurationManager.AppSettings["imgpath"].ToString().Trim() + context.Request.QueryString["sheetid"]; 
        if (!string.IsNullOrEmpty(path)) 
        { 
           FileStream fs = new FileStream(@path, FileMode.Open, FileAccess.Read); 
           Bitmap myImage = new Bitmap(fs); 
            
            MemoryStream ms = new MemoryStream(); 
            myImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); 
            context.Response.ClearContent(); 
            context.Response.ContentType = "image/Jpeg"; 
            context.Response.BinaryWrite(ms.ToArray()); 
        } 
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

你可能感兴趣的:(handler)