asp.net生成缩略图
/// <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生成缩略图的更多相关文章
- ASP.NET生成缩略图的代码
01. // <summary> 02. /// 生成缩略图 03. /// </summary> 04. /// &l ...
- asp.net生成缩略图、文字图片水印
/// <summary> /// 会产生graphics异常的PixelFormat /// </summary> private static PixelFormat[] ...
- ASP.NET 生成缩略图片类分享
/// <summary> /// 生成图片缩略图 指定文件路径生成 /// </summary> public static void SaveImage(String fu ...
- asp.net中生成缩略图并添加版权实例代码
这篇文章介绍了asp.net中生成缩略图并添加版权实例代码,有需要的朋友可以参考一下 复制代码代码如下: //定义image类的对象 Drawing.Image image,newimage; //图 ...
- ASP组件AspJpeg(加水印)生成缩略图等使用方法
ASP组件AspJpeg(加水印)生成缩略图等使用方法 作者: 字体:[增加 减小] 类型:转载 时间:2012-12-17我要评论 ASPJPEG是一款功能相当强大的图象处理组件,用它可以轻松地做出 ...
- asp.net——上传图片生成缩略图
上传图片生成缩略图,原图和缩略图地址一样的时候缩略图会把原图覆盖掉 /// <summary> /// 生成缩略图 /// </summary> /// <param n ...
- .net又一个生成缩略图的方法,不变形
生成缩略图是一个十分常用功能,找到了一个方法,重写部分代码,实用又好用,.net又一个生成缩略图的方法,不变形 /// <summary> /// 为图片生成缩略图 by 何问起 /// ...
- C#上传图片和生成缩略图以及图片预览
因工作需要,上传图片要增加MIME类型验证和生成较小尺寸的图片用于浏览.根据网上代码加以修改做出如下效果图: 前台代码如下: <html xmlns="http://www.w3.or ...
- [原创]超强C#图片上传,加水印,自动生成缩略图源代码
<%@ Page Language=“C#“ AutoEventWireup=“true“ %> <%@ Import Namespace=“System“ %> <%@ ...
随机推荐
- Android 网络请求库volley的封装,让请求更方便
首先封装一下volley 请求 public class CustomRequest extends StringRequest { private static final String TAG = ...
- linux 互信不生效
版权声明:本文为博主原创文章,未经博主允许不得转载. 1. 操作系统版本 1)操作系统 cat /etc/issue cat /etc/issue CentOS release 6.6 (Final ...
- ADT中通过Android SDK Manager去安装x86的image时无法下载
参考:http://www.crifan.com/adt_android_sdk_manager_can_not_download_package_x86_image/
- python: HTML中的选择器
id选择器 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- python学习之字典
1.字典 列表存储的数据比较单一也不够灵活,这时我们可以使用字典来存储某些多内容的数据,字典是无顺序的 1.简单的字典 book={ 'huqiang':13457412571, 'Jasper':1 ...
- Android-Universal-Image-Loader的缓存处理机制
讲到缓存,平时流水线上的码农一定觉得这是一个高大上的东西.看过网上各种讲缓存原理的文章,总感觉那些文章讲的就是玩具,能用吗?这次我将带你一起看过UIL这个国内外大牛都追捧的图片缓存类库的缓存处理机制. ...
- 《BI那点儿事》数据流转换——多播、Union All、合并、合并联接
建立测试数据: CREATE TABLE FactResults ( Name ) , Course ) , Score INT ) INSERT INTO FactResults ( Name , ...
- pyc 文件反编译 py uncompyle2
一.工具 https://github.com/Mysterie/uncompyle2 -----------------------2016-6-3 11:24:19-- source:[1]用un ...
- Windows里面的hosts文件
一.什么是Hosts文件? hosts文件是一个用于储存计算机网络中各节点信息的计算机文件.这个文件负责将主机名映射到相应的IP地址.hosts文件通常用于补充或取代网络中DNS的功能.和DNS不同的 ...
- 使用rman迁移数据库到异机
迁移数据库的方法有多种,较为常用的则是使用RMAN来迁移.使用RMAN迁移数据库属于数据库的物理备份与恢复范畴,整个过程中数据库的相关信息是完整地镜像.因此,基于此种方式还原恢复的数据库用于测试会使得 ...