/**/ /// <summary> /// 裁剪图片 /// </summary> /// <param name="x">开始点x坐标</param> /// <param name="y">开始点y坐标</param> /// <param name="int_Width">宽度</param> /// <param name="int_Height">高度</param> /// <param name="input_ImgUrl">原图</param> /// <param name="out_ImgUrl">生成图</param> public void ImgReduceCutOut( int x, int y, int int_Width, int int_Height, string input_ImgUrl, string out_ImgUrl) ... { int CutOut_Width = 0; // 裁剪的宽度 int CutOut_Height = 0; // 裁剪的高度 int level = 100; //缩略图的质量 1-100的范围 CutOut_Width = int_Width; CutOut_Height = int_Height; System.Drawing.Image oldimage = System.Drawing.Image.FromFile(Server.MapPath(input_ImgUrl)); Bitmap bm = new Bitmap(oldimage); ImageCodecInfo[] ImageCode = ImageCodecInfo.GetImageEncoders(); ImageCodecInfo ii = null; foreach (ImageCodecInfo i in ImageCode) ...{ if (i.MimeType == "image/jpeg") ii = i; } EncoderParameters ep = new EncoderParameters(); ep.Param[0] = new EncoderParameter(Encoder.Quality, (long)level); if (x + CutOut_Width >= bm.Width) CutOut_Width = bm.Width - x; if (y + CutOut_Height >= bm.Height) CutOut_Height = bm.Height - y; Rectangle cloneRect = new Rectangle(x, y, CutOut_Width, CutOut_Height); PixelFormat format = bm.PixelFormat; Bitmap cloneBitmap = bm.Clone(cloneRect, format); cloneBitmap.Save(Server.MapPath(out_ImgUrl), ii, ep); ep.Dispose(); }