将JPG格式的图片制作大小为原图的15%的缩略图的泛型函数

<%@ WebHandler Language="C#" Class="DisplaySmallEuropePicture" %>

using System;
using System.Web;
using Microsoft.VisualBasic.Devices;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

public class DisplaySmallEuropePicture : IHttpHandler 
{    
    public void ProcessRequest (HttpContext context) 
    {
        // 取得传递进来的文件路径。
        string PictureFilePath = context.Request.QueryString["PictureFilePath"].Trim();
                
        // 改变 HTTP 文件头的输出格式,以便让浏览器知道所输出的文件格式是 JPEG 图文件。
        context.Response.ContentType = "Image/JPEG";
        context.Response.Clear();
        context.Response.BufferOutput = true;
                        
        Computer MyComputer = new Computer();
        using (MemoryStream ms = new MemoryStream(MyComputer.FileSystem.ReadAllBytes(PictureFilePath)))
        {
            using (Bitmap bmp = new Bitmap(ms))
            {
                // 将照片缩小。
                using (Bitmap SmallerBmp = new Bitmap(bmp, Convert.ToInt32(bmp.Width * 0.15), Convert.ToInt32(bmp.Height * 0.15)))
                {
                    SmallerBmp.Save(context.Response.OutputStream, ImageFormat.Jpeg);
                }
            }
        }
    }
 
    public bool IsReusable 
    {
        get 
        {
            return false;
        }
    }
}

你可能感兴趣的:(C++,c,Web,浏览器,Microsoft)