C# 图片裁剪
分类: c# DataBase2010-01-14 15:56 1559人阅读 收藏 举报
-
-
-
-
-
-
-
- public void ImgReduceCutOut(int int_Width, int int_Height, string input_ImgUrl, string out_ImgUrl)
- {
-
- int int_Standard_Width = 160;
- int int_Standard_Height = 160;
-
- int Reduce_Width = 0;
- int Reduce_Height = 0;
- int CutOut_Width = 0;
- int CutOut_Height = 0;
- int level = 100;
-
-
- if (int_Standard_Height * int_Width / int_Standard_Width > int_Height)
- {
- Reduce_Width = int_Width;
- Reduce_Height = int_Standard_Height * int_Width / int_Standard_Width;
- CutOut_Width = int_Width;
- CutOut_Height = int_Height;
- }
- else if (int_Standard_Height * int_Width / int_Standard_Width < int_Height)
- {
- Reduce_Width = int_Standard_Width * int_Height / int_Standard_Height;
- Reduce_Height = int_Height;
- CutOut_Width = int_Width;
- CutOut_Height = int_Height;
- }
- else
- {
- Reduce_Width = int_Width;
- Reduce_Height = int_Height;
- CutOut_Width = int_Width;
- CutOut_Height = int_Height;
- }
-
-
- System.Drawing.Image oldimage = System.Drawing.Image.FromFile(Server.MapPath(input_ImgUrl));
-
-
- System.Drawing.Image thumbnailImage = oldimage.GetThumbnailImage(Reduce_Width, Reduce_Height, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
- Bitmap bm = new Bitmap(thumbnailImage);
-
-
- ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
- ImageCodecInfo ici = null;
- foreach (ImageCodecInfo codec in codecs)
- {
- if (codec.MimeType == "image/jpeg")
- ici = codec;
- }
- EncoderParameters ep = new EncoderParameters();
- ep.Param[0] = new EncoderParameter(Encoder.Quality, (long)level);
-
-
-
-
- Rectangle cloneRect = new Rectangle(0, 0, CutOut_Width, CutOut_Height);
- PixelFormat format = bm.PixelFormat;
- Bitmap cloneBitmap = bm.Clone(cloneRect, format);
-
-
- cloneBitmap.Save(Server.MapPath(out_ImgUrl), ici, ep);
- }
原文地址:https://www.cnblogs.com/xianyin05/p/3071140.html