#region 图像处理
/// <summary>
/// 生成缩略图
/// </summary>
/// <param name="M_OriginalImagePath">源图路径(物理路径)</param>
/// <param name="M_ThumbnailPath">缩略图路径(物理路径)</param>
/// <param name="M_Width">缩略图宽度</param>
/// <param name="M_Height">缩略图高度</param>
public static void MakeThumbnail(string M_OriginalImagePath, string M_ThumbnailPath, int M_Width, int M_Height)
{
System.Drawing.Image originalImage = System.Drawing.Image.FromFile(M_OriginalImagePath);
int towidth = 0;
int toheight = 0;
if (originalImage.Width >= M_Width && originalImage.Height <= M_Height)
{
towidth = M_Width;
toheight = originalImage.Height;
}
if (originalImage.Width <= M_Width && originalImage.Height >= M_Height)
{
towidth = originalImage.Width;
toheight = M_Height;
}
if (originalImage.Width >= M_Width && originalImage.Height >= M_Height)
{
towidth = M_Width;
toheight = M_Height;
}
if (originalImage.Width <= M_Width && originalImage.Height <= M_Height)
{
towidth = originalImage.Width;
toheight = originalImage.Height;
}
int x = 0;//左上角的x坐标
int y = 0;//左上角的y坐标
//新建一个bmp图片
System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);
//新建一个画板
Graphics g = System.Drawing.Graphics.FromImage(bitmap);
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//清空画布并以透明背景色填充
g.Clear(Color.Transparent);
//在指定位置并且按指定大小绘制原图片的指定部分
g.DrawImage(originalImage, x, y, towidth, toheight);
try
{
//以jpg格式保存缩略图
bitmap.Save(M_ThumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (System.Exception e)
{
throw e;
}
finally
{
originalImage.Dispose();
bitmap.Dispose();
g.Dispose();
}
}
#endregion
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wangjun8868/archive/2008/11/12/3283493.aspx
分享到:
相关推荐
解决.net缩略图质量问题 Asp.net生成高质量缩略图
原类生成的缩略图的问题在于:高或者宽可能会大于需求值。比如,我需要的图片宽为150,高为120,当原图 * 高为150,宽为150或差距不大时,生成的图片不会有变化,即也是高150,宽150,这样,当把这些图片显示到网页...
asp.net生成高质量缩略图通用函数(c#代码),支持多种生成方式
/// <summary> /// 生成缩略图 /// </summary> /// 源图路径(物理路径)</param> /// 缩略图路径(物理路径)</param> /// 缩略图宽度</param> /// 缩略图高度</param> /// ...
在asp.net中,上传图片功能或者是常用的,生成缩略图也是常用的。baidu或者google,c#的方法也是很多的,但是一用却发现缩略图不清晰啊,缩略图片太大之类的事情,下面是我在处理图片上的代码,效果不错,所以拿出来...
asp.net 自动生成缩略图,asp.net 自动生成缩略图,asp.net 自动生成缩略图
可以根据不同参数生成缩略图片,而且不变形
本文详细介绍在ASP.NET中上传图片并生成缩略图 在ASP.NET中上传图片并生成缩略图!
用asp.net做的网页缩略图源码 用asp.net做的网页缩略图源码 用asp.net做的网页缩略图源码
Asp.net图片生成缩略图 Asp.net图片生成缩略图
asp.net上传图片 生成缩略图 并保存到数据库 从数据库读取图片
asp.net图片上传生成缩略图和水印 asp.net教材,新手上路的武器
ASP.NET图片生成缩略图(VB.NET),高宽自定义
asp.net生成缩略图通用简单函数 asp.net生成缩略图通用简单函数
ASP.Net 上传图片并生成高清晰缩略图的代码
asp.net生成缩略图通用函数(支持多种生成方式)_支持图片裁减
ASP.NET生成图片验证码 ASP.NET生成图片验证码 ASP.NET生成图片验证码
/// <summary> /// 生成缩略图 /// </summary> /// ”originalImagePath”>源图路径(物理路径)</param> /// ”thumbnailPath”>缩略图路径(物理路径)</param> /// ”width”>缩略图宽度</param> /// ”...