/// <summary>
/// 生成缩略图
/// </summary>
/// <param name="orginalImagePat">原图片地址</param>
/// <param name="thumNailPath">缩略图地址</param>
/// <param name="width">缩略图宽度</param>
/// <param name="height">缩略图高度</param>
/// <param name="model">生成缩略的模式</param>
public void MakeThumNail(string originalImagePath, string thumNailPath, int width, int height, string model)
{
System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath); int thumWidth = width; //缩略图的宽度
int thumHeight = height; //缩略图的高度 int x = ;
int y = ; int originalWidth = originalImage.Width; //原始图片的宽度
int originalHeight = originalImage.Height; //原始图片的高度
switch (model)
{
case "HW": //指定高宽缩放,可能变形
break;
case "W": //指定宽度,高度按照比例缩放
thumHeight = originalImage.Height * width / originalImage.Width;
break;
case "H": //指定高度,宽度按照等比例缩放
thumWidth = originalImage.Width * height / originalImage.Height;
break;
case "Cut":
if ((double)originalImage.Width / (double)originalImage.Height > (double)thumWidth / (double)thumHeight)
{
originalHeight = originalImage.Height;
originalWidth = originalImage.Height * thumWidth / thumHeight;
y = ;
x = (originalImage.Width - originalWidth) / ;
}
else
{
originalWidth = originalImage.Width;
originalHeight = originalWidth * height / thumWidth;
x = ;
y = (originalImage.Height - originalHeight) / ;
}
break;
default:
break;
} //新建一个bmp图片
System.Drawing.Image bitmap = new System.Drawing.Bitmap(thumWidth, thumHeight);
//新建一个画板
System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(bitmap);
//设置高质量查值法
graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//清空画布并以透明背景色填充
graphic.Clear(System.Drawing.Color.Transparent);
//在指定位置并且按指定大小绘制原图片的指定部分
graphic.DrawImage(originalImage, new System.Drawing.Rectangle(, , thumWidth, thumHeight)
, new System.Drawing.Rectangle(x, y, originalWidth, originalHeight), System.Drawing.GraphicsUnit.Pixel);
try
{
bitmap.Save(thumNailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{ throw ex;
}
finally
{
originalImage.Dispose();
bitmap.Dispose();
graphic.Dispose();
}
}

asp.net生成缩略图的更多相关文章

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

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

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

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

  3. ASP.NET 生成缩略图片类分享

    /// <summary> /// 生成图片缩略图 指定文件路径生成 /// </summary> public static void SaveImage(String fu ...

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

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

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

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

  6. asp.net——上传图片生成缩略图

    上传图片生成缩略图,原图和缩略图地址一样的时候缩略图会把原图覆盖掉 /// <summary> /// 生成缩略图 /// </summary> /// <param n ...

  7. .net又一个生成缩略图的方法,不变形

    生成缩略图是一个十分常用功能,找到了一个方法,重写部分代码,实用又好用,.net又一个生成缩略图的方法,不变形 /// <summary> /// 为图片生成缩略图 by 何问起 /// ...

  8. C#上传图片和生成缩略图以及图片预览

    因工作需要,上传图片要增加MIME类型验证和生成较小尺寸的图片用于浏览.根据网上代码加以修改做出如下效果图: 前台代码如下: <html xmlns="http://www.w3.or ...

  9. [原创]超强C#图片上传,加水印,自动生成缩略图源代码

    <%@ Page Language=“C#“ AutoEventWireup=“true“ %> <%@ Import Namespace=“System“ %> <%@ ...

随机推荐

  1. ubuntu 如何 su 到 root(作为 root 用户操作)

    ubuntu 安装后,root用户默认被锁定,不允许登录,也不允许"su"到 root.对于桌面用户来说,这样安全性更高一些,但对于服务器可以设置成"允许 su 到roo ...

  2. LeetCode----172. Factorial Trailing Zeroes(Java)

    package singlenumber136; //Given an array of integers, every element appears twice except for one. F ...

  3. Auty自动化测试框架第五篇——框架内部的调用支持、自动化安装库与配置说明

    [本文出自天外归云的博客园] 本次对Auty自动化测试框架做些收尾工作,由于在scripts文件夹中的脚本会需要调用其他包结构文件夹中的脚本,所以这里需要添加一下框架对于内部脚本间互相调用的支持,这里 ...

  4. python学习之for语句

    1.range数字范围 for i in range(5): print (i) 结果显示: 0 1 2 3 4 2.列表显示 ']: print ("current num:", ...

  5. R开发环境(Eclipse+StatET)

    引用:http://cos.name/2008/12/eclipse-statet-for-r-editor/ StatET(www.walware.de/goto/statet) 1. 安装软件 s ...

  6. 深入浅出设计模式——代理模式(Proxy Pattern)

    模式动机在某些情况下,一个客户不想或者不能直接引用一个对象,此时可以通过一个称之为“代理”的第三者来实现间接引用.代理对象可以在客户端和目标对象之间起到中介的作用,并且可以通过代理对象去掉客户不能看到 ...

  7. 《BI那点儿事》三国数据分析系列——蜀汉五虎上将与魏五子良将武力分析,绝对的经典分析

    献给广大的三国爱好者们,希望喜欢三国的朋友一起讨论,加深对传奇三国时代的了解 数据分析基础概念:集中趋势分析是指在大量测评数据分布中,测评数据向某点集中的情况.总体(population)是指客观存在 ...

  8. xml资源getStringArray(R.array.xxx)方法

    在res/values/下新建menu_names.xml 代码如下: <?xml version="1.0" encoding="utf-8"?> ...

  9. lamp centos虚拟主机配置

    1.基于不同端口的虚拟主机配置 [root@lamp~]# vi /etc/httpd/conf/httpd.conf Listen 80      #设置监听不同的虚拟主机需要使用的端口 Liste ...

  10. JavaScript学习笔记及知识点整理_1

    一.js的基础部分 1.==和===的区别:==在判断是否相等的时候会进行类型转换,有时会得到非常奇怪的结果,因此一般情况下都是用===判断是否相等2.strict模式:在js中,如果一个变量没有用v ...