All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
Sql,Server数据库定时自动备份_[SQL,Server教程]
VS2005之C#项目调试问题解决方案集锦_.net资料_编程技术
PHP实例:PHP取GB2312编码字符串首字母的方法_php资料_编程技术
Asp.Net实例:创建自滚动的DataGrid_[Asp.Net教程]
SQL,Server中发送邮件的新方式_[SQL,Server教程]
数据仓库数据建模的几种思路_mssql学习_编程技术
PHP开发技巧:PHP关于图像颜色的操作_php资料_编程技术
MySQL手册_php资料_编程技术
优秀ASP.NET程序员修炼之路_[Asp.Net教程]
在AJAX程序中实现互斥揭秘_[AJAX教程]
Reading number is top 10 pictures
含苞欲放的素颜美少女2
Steal to eat bacon bird
LiXiang early youth photo
男人巳快沦落成动物了
西班牙山村小景4
The real super beauty15
超级大兔子
这张图有两句话,你看出来了吗?
2015中美最新武器装备巅峰对决!
Sora aoi on twitter2
Download software ranking
linux高级编程
The Bermuda triangle2
Sora aoi, the nurse, uniform ,nursing assistant
Unix video tutorial2
I'm come from Beijing1
Boxer vs Yellow3
matrix2
Boxer vs Yellow2
Boxer's Top ten classic battle2
Tram sex maniac 2 (H) rar bag3
aaa published in(发表于) 2013/12/6 10:25:31 Edit(编辑)
ASP.NET生成高质量缩略图通用函数

ASP.NET生成高质量缩略图通用函数

ASP.NET生成高质量缩略图通用函数(c#代码)_.net资料_编程技术-数科优化网

在网站开发时,生成缩略图是一个非常常见和实用的功能.以前在asp里只能借助com组件实现,现在在.net里可以利用框架的强大的类库轻松实现.下面帖出完整的代码(带详细注释),参考了网上的一些文章及.net sdk相关内容.QQROOM网络家园的图片上传用到了所有的4种生成方式.
///


/// 生成缩略图
///

/// 源图路径(物理路径)
/// 缩略图路径(物理路径)
/// 缩略图宽度
/// 缩略图高度
/// 生成缩略图的方式
public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode)
{
Image originalImage = Image.FromFile(originalImagePath);

int towidth = width;
int toheight = height;

int x = 0;
int y = 0;
int ow = originalImage.Width;
int oh = originalImage.Height;


switch (mode)
{
case "HW"://指定高宽缩放(可能变形)
break;
case "W"://指定宽,高按比例
toheight = originalImage.Height * width/originalImage.Width;
break;
case "H"://指定高,宽按比例
towidth = originalImage.Width * height/originalImage.Height;
break;
case "Cut"://指定高宽裁减(不变形)
if((double)originalImage.Width/(double)originalImage.Height > (double)towidth/(double)toheight)
{
oh = originalImage.Height;
ow = originalImage.Height*towidth/toheight;
y = 0;
x = (originalImage.Width - ow)/2;
}
else
{
ow = originalImage.Width;
oh = originalImage.Width*height/towidth;
x = 0;
y = (originalImage.Height - oh)/2;
}
break;
default :
break;
}

//新建一个bmp图片
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, new Rectangle(0, 0, towidth, toheight),
new Rectangle(x, y, ow,oh),
GraphicsUnit.Pixel);


try
{
//以jpg格式保存缩略图
bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch(System.Exception e)
{
throw e;
}
finally
{
originalImage.Dispose();
bitmap.Dispose();
g.Dispose();
}
}






添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.