首页 > Web开发 > 详细

.net 裁剪图片

时间:2015-07-27 14:31:36      阅读:217      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!