ASP.NET生成缩略图失真非常厉害,如果图像原文件为JPG格式的,可以通过以下程序优化!!!如果是其它格式的图片可以在上传时候保存为JPG格式的,详情情参见 http://blog.csdn.net/rheleven/archive/2005/03/21/325540.aspx
C#版本:
private void MakeSLT(string oldImagePath,string newImagePath)
{
//oldImagePath -原图地址 newImagePath 生成缩略图地址
int width = 150;//缩略图的宽度
int height = 112;// 缩略图的高度
int level = 100; //缩略图的质量 1-100的范围
System.Drawing.Image oldimage = System.Drawing.Image.FromFile(oldImagePath);
System.Drawing.Image thumbnailImage = oldimage.GetThumbnailImage(width, height,new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
Bitmap bm=new Bitmap(thumbnailImage);
//处理JPG质量的函数
ImageCodecInfo[] codecs=ImageCodecInfo.GetImageEncoders();
ImageCodecInfo ici=null;
foreach(ImageCodecInfo codec in codecs)
{
if(codec.MimeType=="image/jpeg")
ici=codec;
}
EncoderParameters ep=new EncoderParameters();
ep.Param[0]=new EncoderParameter(Encoder.Quality,(long)level);
bm.Save(newImagePath,ici,ep);
}
VB.NET版本:
Sub makeSLT(ByVal oldImagePath As String,ByVal newImagePath As String)
Dim oimg As System.Drawing.Image = System.Drawing
| 对此文章发表了评论 |

