/// <summary>
/// 生成图片缩略图 指定文件路径生成
/// </summary>
public static void SaveImage(String fullName, string fileName, int w, int h)
{
FileStream fs = new FileStream(fullName, FileMode.Open);
System.Drawing.Image image = System.Drawing.Image.FromStream(fs, true);
fs.Close();
SaveImage(image, fileName, w, h);
} /// <summary>
/// 生成图片缩略图 指定文件流生成
/// </summary>
public static void SaveImage(Stream fs, string fileName, int w, int h)
{
Image image = System.Drawing.Image.FromStream(fs, true);
SaveImage(image, fileName, w, h);
} /// <summary>
/// 生成图片缩略图
/// </summary>
public static void SaveImage(System.Drawing.Image image, string fileName, int w, int h, int high = 90)
{
if (w == 0 && h == 0)
{
w = image.Width;
h = image.Height;
}
else if (w > 0 && h > 0)
{
if (image.Width > image.Height)
{
if (image.Width > w)
{
h = (int)(image.Height * ((decimal)w / image.Width));
}
else
{
h = image.Height;
w = image.Width;
}
}
else
{
if (image.Height > h)
{
w = (int)(image.Width * ((decimal)h / image.Height));
}
else
{
h = image.Height;
w = image.Width;
}
}
}
else if (w > 0)
{
if (image.Width > w)
{
h = (int)(image.Height * ((decimal)w / image.Width));
}
else
{
h = image.Height;
w = image.Width;
}
}
else if (h > 0)
{
if (image.Height > h)
{
w = (int)(image.Width * ((decimal)h / image.Height));
}
else
{
h = image.Height;
w = image.Width;
}
} Bitmap ret = new Bitmap(w, h); using (Graphics g = Graphics.FromImage(ret))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.FillRectangle(Brushes.White, 0, 0, w, h);
g.DrawImage(image, 0, 0, w, h);
EncoderParameters parms = new EncoderParameters();
long[] quality = new long[1];
quality[0] = high;
EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
parms.Param[0] = parm;
ImageCodecInfo[] arr = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo ar = null;
for (int x = 0; x < arr.Length; x++)
{
if (arr[x].FormatDescription.Equals("JPEG"))
{
ar = arr[x];
break;
}
} ret.Save(fileName, ar, parms);
ret.Dispose();
image.Dispose();
}
}

ASP.NET 生成缩略图片类分享的更多相关文章

  1. asp.net生成缩略图

    /// <summary> /// 生成缩略图 /// </summary> /// <param name="orginalImagePat"> ...

  2. ASP.NET生成缩略图的代码

    01.        // <summary> 02.        /// 生成缩略图 03.        /// </summary> 04.        /// &l ...

  3. asp.net生成缩略图、文字图片水印

    /// <summary> /// 会产生graphics异常的PixelFormat /// </summary> private static PixelFormat[] ...

  4. [GDI+] 生成缩略图的类文件SmallImage (转载)

    直接看代码吧,大家可以直接复制使用 /// <summary> /// 类说明:SmallImage类, /// 编码日期:2012-08-20 /// 编 码 人: 苏飞 /// 联系方 ...

  5. 【PHP缩略图类】手机照片不能生成缩略图问题以及解决方式

    [本文原创,谢绝转载] 一.出现的问题 这几天做了手机上传照片并裁出缩略图的接口的測试,发现无论怎么.生成的缩略图都是一片漆黑.:-( 然后就把这个缩略图类单拿出来进行測试,发现仅仅要是手机拍出来的照 ...

  6. asp.net中生成缩略图并添加版权实例代码

    这篇文章介绍了asp.net中生成缩略图并添加版权实例代码,有需要的朋友可以参考一下 复制代码代码如下: //定义image类的对象 Drawing.Image image,newimage; //图 ...

  7. ASP组件AspJpeg(加水印)生成缩略图等使用方法

    ASP组件AspJpeg(加水印)生成缩略图等使用方法 作者: 字体:[增加 减小] 类型:转载 时间:2012-12-17我要评论 ASPJPEG是一款功能相当强大的图象处理组件,用它可以轻松地做出 ...

  8. php 图片操作类,支持生成缩略图,添加水印,上传缩略图

    <?php class Image {     //类开始     public $originimage = ""; //源图片文件地址     public $image ...

  9. PHP生成缩略图的一个方法类(转)

    //使用如下类就可以生成图片缩略图 class resizeimage { //图片类型 var $type; //实际宽度 var $width; //实际高度 var $height; //改变后 ...

随机推荐

  1. python爬搜狗微信获取指定微信公众号的文章

    前言: 之前收藏了一个叫微信公众号的文章爬取,里面用到的模块不错.然而 偏偏报错= =.果断自己写了一个 正文: 第一步爬取搜狗微信搜到的公众号: http://weixin.sogou.com/we ...

  2. 温故而知新-strtok函数

    温故而知新-strtok函数 记得之前没见过这个函数,是把字符串分割成更小的字符串 来个例子就是比较鲜明了 $string = "Hello world. Beautiful day tod ...

  3. [代码]multimap员工分组案例

    案例要求: //multimap 案例//公司今天招聘了 5 个员工,5 名员工进入公司之后,需要指派员工在那个部门工作//人员信息有: 姓名 年龄 电话 工资等组成//通过 Multimap 进行信 ...

  4. STL string 常用函数(转)

    string类的构造函数: string(const char *s); //用c字符串s初始化 string(int n,char c); //用n个字符c初始化 此外,string类还支持默认构造 ...

  5. Git----时光穿梭机之撤销修改05

    自然,你是不会犯错,不过现在是凌晨两点,你正在赶一份工作报告,你在readme.txt中添加了一行: $ cat readme.txtGit is a distributed version cont ...

  6. Cloudera Manger CDH 安装文档

    简介: Cloudera Manager 是 Cloudera 公司推出的 Hadoop 集群管理工具,通过该管理工具可以方便的部署.配置.监控集群. Cloudera 公司自己发布的 Hadoop ...

  7. CTC 的工作原理

    CTC 的工作原理     Fig. 1. How CTC  combine a word (source: https://distill.pub/2017/ctc/) 这篇文章主要解释CTC 的工 ...

  8. 41. First Missing Positive (HashTable)

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  9. JS 将json数组转为嵌套层级数组

    ele UI 的树级菜单的数据要求是这种嵌套的,但是Ztree的老用发的是 var zNodes =[ { id:, pId:, name:"zTree Home", pid:0} ...

  10. Python 入门学习(壹)上机时间提醒

    基于 Udacity 的 Python 入门课程 Programming Foundations with Python 基于 Python 2.7 控制台版本 思路 Project 1 是一个时间提 ...