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(); }