-
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);
- }
-
相关阅读:
yepnope.js 异步加载资源文件
省心选房5步走 买房前先算经济账还要多打听
css中inline、block、inlineblock的区别
web标准化设计:常用的CSS命名规则
用css的手段解决Google Chrome浏览器的字体最小12px问题
HTML元素的默认样式
CSS中 常见中文字体的英文名称
《重构 改善既有代码的设计》书摘
手机号码匹配规则
WEB开发——大批量数据导出经验谈
-
原文地址:https://www.cnblogs.com/xianyin05/p/3071140.html
Copyright © 2020-2023
润新知