码迷,mamicode.com
首页 > Web开发 > 详细

.net 裁剪图片

时间:2015-07-27 14:34:43      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

 

private void GetImg()
{

if (Request.Files.Count < 1)
{
return;
}


var imgup = Request.Files[0];


string[] imgsize = Request["imgsize"].Split(&);
int x = Convert.ToInt32(decimal.Parse(imgsize[0].ToString()));
int y = Convert.ToInt32(decimal.Parse(imgsize[1].ToString()));

int w = Convert.ToInt32(decimal.Parse(imgsize[2].ToString()));
int h = Convert.ToInt32(decimal.Parse(imgsize[3].ToString()));
Stream stream = imgup.InputStream;

//定义截取矩形
System.Drawing.Rectangle cropArea = new System.Drawing.Rectangle(x, y, w, h); //要截取的区域大小
//加载图片
//System.Drawing.Image img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(System.IO.File.ReadAllBytes(oldPath)));
System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
//定义Bitmap对象
System.Drawing.Bitmap bmpImage = new System.Drawing.Bitmap(img);
//进行裁剪
System.Drawing.Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);

//保存成新文件
bmpCrop.Save(Server.MapPath("~") + "/jcrop/aaa.jpg");


//释放对象
bmpImage.Dispose();
img.Dispose();
bmpCrop.Dispose();
}

 

.net 裁剪图片

标签:

原文地址:http://www.cnblogs.com/sxmny/p/4679945.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!