生成缩约图时的图像质量问题?

powbcom 2004-08-11 02:36:08
在上传图片时,较大的图片上传生成稍小点的缩约图时质量下降严重,请高手帮助解决,谢啦!

代码如下:

BigImg = UpImg.GetThumbnailImage(ImgW, ImgH, CallB, IntPtr.Zero)
BigImg.Save(Filepath, Imaging.ImageFormat.Jpeg)
BigImg.Dispose()
...全文
156 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
newnan 2004-08-26
  • 打赏
  • 举报
回复
/// <summary>
/// 不失真获得缩微图
/// </summary>
/// <returns></returns>
public bool GetThumbImg()
{
try
{
string imgpath;//原始路径
if(imgsourceurl.IndexOf("\\",0)<0)//使用的是相对路径
{
imgpath=HttpContext.Current.Server.MapPath(imgsourceurl);//转化为物理路径
}
else
{
imgpath=imgsourceurl;
}
System.Drawing.Image sourceImage = System.Drawing.Image.FromFile(imgpath);
int width = sourceImage.Width;
int height = sourceImage.Height;
if(thumbwidth<=0)
{
thumbwidth=120;
}
if(thumbwidth>=width)
{
return false;
}
else
{
//关键在这里:
Image imgThumb=new System.Drawing.Bitmap(thumbwidth,height*thumbwidth/width);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(imgThumb);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(sourceImage, new Rectangle(0, 0, thumbwidth,height*thumbwidth/width), 0, 0, width, height, GraphicsUnit.Pixel);
string thumbpath="";
sourceImage.Dispose();
//myBitmap.Dispose();
if(thumburl=="")
{
//File.Delete(HttpContext.Current.Server.MapPath(imgpath));
thumbpath=imgpath;
}

if(thumbpath.IndexOf("\\",0)<0)//使用的是相对路径
{
thumbpath=HttpContext.Current.Server.MapPath(thumburl);//转化为物理路径
}

imgThumb.Save(thumbpath,ImageFormat.Jpeg);
imgThumb.Dispose();
return true;
}
}
catch
{
throw;
}
}
daou101 2004-08-12
  • 打赏
  • 举报
回复
http://dotnet.aspx.cc/ShowDetail.aspx?id=45E7E33C-F149-450E-B5D5-832958C20538

孟子的文章解决了。
powbcom 2004-08-12
  • 打赏
  • 举报
回复
缩略图是按比例的
guying999 2004-08-12
  • 打赏
  • 举报
回复
参考:
http://dotnet.aspx.cc/ShowDetail.aspx?id=45E7E33C-F149-450E-B5D5-832958C20538
guying999 2004-08-12
  • 打赏
  • 举报
回复
生成缩略图的尺寸比例要和原图的一致,你可以通过image对象取得要生成缩略图图象的尺寸然后算出它的比例,生成缩略图时也要按照这种比例
hertcloud 2004-08-12
  • 打赏
  • 举报
回复
http://www.microsoft.com/china/msdn/archives/library/dnaspp/html/colorquant.asp
jonescheng 2004-08-12
  • 打赏
  • 举报
回复
你缩图的时候指定的图片的比例,所以你的源图也需要
和指定的比例一样。。。
xueqs 2004-08-12
  • 打赏
  • 举报
回复
Imaging.ImageFormat.Jpeg

改一下图片格式试一下
wnlovezxm 2004-08-12
  • 打赏
  • 举报
回复
不好意思没做过,帮你顶!
powbcom 2004-08-12
  • 打赏
  • 举报
回复
晕倒,没有人解答啊?
powbcom 2004-08-11
  • 打赏
  • 举报
回复
有人解答吗?
gucs 2004-08-11
  • 打赏
  • 举报
回复
有什么好办法吗?期待中!

呵呵,别告诉我自己写一个

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧