📄 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 + -