[GDI+]如何制作出高质量的缩略图

如何制作出高质量的缩略图是个关键的因素,最近项目中遇到了类似需要解决的问题。
一般情况下,我们制作成的缩略图都会保存为占用空间比较小的Jpeg类型,在使用GetThumbnail方法制作成的缩略图质量感觉不理想,
如何才能保证在压缩比例最优化的情况下产生高质量的缩略图呢,经过查阅相关资料,
发现在Graphics 对象的 InterpolationMode 属性中可以产生不同质量模式的缩放图,看到这里了,不再是缩略图,而是缩放图,就是说放大的时候也可以使用。
Graphics 对象的 InterpolationMode 属性枚举定义了几种模式,列表如下:
NearestNeighbor
Bilinear
HighQualityBilinear
Bicubic
HighQualityBicubic
从名字上就可以识别NearestNeighbor 是质量最差的模式,HighQualityBicubic 是质量最好的模式了,我们借此属性看看生成的图片怎么样吧,下段代码摘自网络,大家可以把下面的函数拿去使用,这里采用了HighQualityBilinear 。

代码引用地址: http://www.bobpowell.net/highqualitythumb.htm
ExpandedBlockStart.gif ContractedBlock.gif      Public   Function GenerateThumbnail() Function GenerateThumbnail(original As Image, percentage As IntegerAs Image
InBlock.gif
InBlock.gif     
If percentage < 1 Then
InBlock.gif
InBlock.gif      
Throw New Exception("Thumbnail size must be aat least 1% of the original size")
InBlock.gif
InBlock.gif     
End If
InBlock.gif
InBlock.gif     
Dim tn As New Bitmap(CInt(original.Width * 0.01F * percentage), _
InBlock.gif
InBlock.gif                          
CInt(original.Height * 0.01F * percentage))
InBlock.gif
InBlock.gif     
Dim g As Graphics = Graphics.FromImage(tn)
InBlock.gif
InBlock.gif     g.InterpolationMode 
= InterpolationMode.HighQualityBilinear 
InBlock.gif

InBlock.gif     g.DrawImage(original, 
New Rectangle(00, tn.Width, tn.Height), _
InBlock.gif
InBlock.gif                 
00, original.Width, original.Height, GraphicsUnit.Pixel)
InBlock.gif
InBlock.gif     g.Dispose()
InBlock.gif
InBlock.gif     
Return CType(tn, Image)
InBlock.gif
ExpandedBlockEnd.gif    
End Function
 
None.gif

None.gif

转载于:https://www.cnblogs.com/hbzxf/archive/2005/01/26/97697.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值