?? handler.ashx
字號:
?<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Collections;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/jpeg";
context.Response.BufferOutput =true;
double MaxLength =100;
if ( context.Request.QueryString["filename"] != null)
{
//取得原圖
string filename =context. Request.QueryString["filename"];
Bitmap bmpOld = new Bitmap(context.Server.MapPath("~/upload/" + filename));
//計算縮小比例
double d1;
if (bmpOld.Height > bmpOld.Width)
d1 = (double)(MaxLength / (double)bmpOld.Width);
else
d1 = (double)(MaxLength / (double)bmpOld.Height);
//產生縮圖
Bitmap bmpThumb = new Bitmap(bmpOld, (int)(bmpOld.Width * d1), (int)(bmpOld.Height * d1));
// 清除緩沖
context. Response.Clear();
//生成圖片
bmpThumb.Save(context.Response.OutputStream, ImageFormat.Jpeg);
context.Response.End();
//釋放資源
bmpThumb.Dispose();
bmpOld.Dispose();
context.Response.Flush();
}
}
public bool IsReusable
{
get { return false;}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -