缩略图
context.Response.ContentType = "image/jpeg";
string path = context.Request.MapPath("03.jpg");
//原图
using (Image img = Image.FromFile(path))
{
//保持横纵比例
int width = 150;
int height = 100;
if (img.Width > img.Height)
{
height = width * img.Height / img.Width;
}
else
{
width = height * img.Width / img.Height;
}
//缩略图
using (Bitmap bitmap = new Bitmap(width, height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.DrawImage(img, 0, 0,bitmap.Width,bitmap.Height);
bitmap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}