public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "image/jpeg";
//url传来的图片名
string img = context.Request.QueryString["img"];
if (!string .IsNullOrEmpty(img))
{
//获取图片的物理路径
string path = context.Request.MapPath("images/"+img);
//加载大图
Image big = Image.FromFile(path);

int oldWidth = big.Width;
int oldHeigth = big.Height;
int newWidth = 150;
int newHeigth = 100;
//保持纵横比例
if (oldWidth > oldHeigth)
{
newHeigth = newWidth * oldHeigth / oldWidth;
}
else
{
newWidth = newHeigth * oldWidth / oldHeigth;
}

//生成小图
Bitmap bitmap = new Bitmap(newWidth,newHeigth);

Graphics g = Graphics.FromImage(bitmap);
//把大图,画到小图上
g.DrawImage(big,0,0,bitmap.Width,bitmap.Height);
//释放资源
g.Dispose();
//把bitmap输出到浏览器
bitmap.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);

}

}

 

posted on 2011-12-01 22:15  幻想时空  阅读(445)  评论(0编辑  收藏  举报