ClassLibraryWeiBao/IZWebFileManager/ThumbnailHandler.cs

(完整代码) 1KB

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;

namespace IZ.WebFileManager
{
    public class ThumbnailHandler : IHttpHandler
    {
        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "image/jpeg";
            int size = 92;

            string vPath = HttpUtility.UrlDecode(context.Request.Url.Query.Substring(1));
            string path = context.Request.MapPath(vPath);

            using (var original = Image.FromFile(path))
            {
                if (original.Width > size || original.Height > size)
                {
                    int tw = original.Width > original.Height ? size : (original.Width * size) / original.Height;
                    int th = original.Width > original.Height ? (original.Height * size) / original.Width : size;

                    using (var thumb = original.GetThumbnailImage(tw, th, null, IntPtr.Zero))
                    {
                        thumb.Save(context.Response.OutputStream, ImageFormat.Jpeg);

                    }
                }
                else
                {
                    original.Save(context.Response.OutputStream, ImageFormat.Jpeg);
                }
            }

        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。