图片等比例截取
来源:互联网 发布:淘宝卖茶叶图片大全 编辑:程序博客网 时间:2024/04/28 22:04
private static bool ThumbnailCallback()
{
return false;
}
//****************************************************************************
//设置高质量插值法
//g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
//g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//清空画布并以透明背景色填充
//g.Clear(Color.Transparent);
//****************************************************************************
/// <summary>
/// 图片智能截取
/// </summary>
/// <returns></returns>
public static bool IntellectiveCut(string srcPath, string destPath, double width, double height)
{
System.Drawing.Image img = new Bitmap(srcPath);
//生成图片大小必需小于原图
if (width > img.Width || height > img.Height)
return false;
//删除的高度,与宽度
double cutWidth, cutHeight;
cutWidth =(img.Width * height/ img.Height -width); //宽度切割,高度缩放
cutHeight = (img.Height * width /img.Width-height);//高度切割,宽度缩放
byte flag=0;//0 截高,1 截宽
flag =(byte)( cutHeight < cutWidth ? 0 : 1);
if (cutWidth >= 0 && cutHeight < 0)
flag = 1;
if (cutHeight >= 0 && cutWidth < 0)
flag = 0;
//System.Drawing.Image.GetThumbnailImageAbort myCallback=new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
System.Drawing.Image thumImg;
if (flag == 0)
thumImg = new Bitmap(img,(int)width, (int)height + (int)cutHeight); //img.GetThumbnailImage((int)width, (int)height + (int)cutHeight, myCallback, IntPtr.Zero);
else
thumImg = new Bitmap(img,(int)width + (int)cutWidth, (int)height);// img.GetThumbnailImage((int)width + (int)cutWidth, (int)height, myCallback, IntPtr.Zero);
System.Drawing.Bitmap destImg = new Bitmap((int)width, (int)height);
Graphics g = Graphics.FromImage(destImg);
Rectangle rect = new Rectangle(0, 0, (int)width,(int) height);
g.DrawImage(thumImg, rect, rect, GraphicsUnit.Pixel);
g.Save();
destImg.Save(destPath,ImageFormat.Jpeg);
thumImg.Dispose();
img.Dispose();
destImg.Dispose();
return true;
}
- 图片等比例截取
- 图片等比例截取
- //等比例缩小图片
- 图片等比例缩小
- 图片等比例自适应
- 图片等比例缩放
- 图片等比例缩放
- 等比例压缩图片
- JS等比例图片
- 图片等比例缩放
- 图片等比例缩放
- 图片等比例缩放
- 图片等比例缩放
- 等比例缩放图片
- 等比例缩放图片
- 图片等比例压缩
- 等比例缩放图片
- 图片等比例压缩
- 14.9.10 The as operator
- 14.10 Logical operators
- 14.11 Conditional logical operators
- 当Spring遇到Ruby
- ASP源码现阶段最好的保护方案软件特点:无需改动原网站代码,无需写成DLL。加解快速方便。加密后的密文能法解密。
- 图片等比例截取
- [免费]新增日期控件的下载
- tomcat中文路径名问题的解决
- 技术评论:明天,中间件在哪?
- 画图问题
- 学习C++50个观点
- 第一章 基本概念 1.1 算法
- 首都人才在线网站,流氓网站
- test