Torna al Thread
<%@ WebHandler Language="C#" Class="Thumb" %>
using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Web.SessionState;
public class Thumb : IHttpHandler, IRequiresSessionState
{
bool ThumbnailCallback()
{
return false;
}
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
Image.GetThumbnailImageAbort callback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
Bitmap bmp;
Image thumb;
string file = string.Empty;
string path = context.Server.MapPath("./" + context.Request.QueryString["nomefile"]);
//--- dimensioni della thubnail
double width = 100;
double height = 100;
bmp = new Bitmap(path);
width = bmp.Width;
height = bmp.Height;
//--- calcolo le proporzioni
if (bmp.Width > width)
{
double prop = width/bmp.Width;
height = (int)(prop * bmp.Height);
}
//--- creo la thumbnail con quelle dimensioni
thumb = bmp.GetThumbnailImage(width, height, callback, IntPtr.Zero);
//--- scrivo negli header che è un'immagine
context.Response.AddHeader("Content-Type", "image/jpeg");
thumb.Save(context.Response.OutputStream, ImageFormat.Jpeg);
thumb.Dispose();
bmp.Dispose();
}
}