Csharp/C#教程:C#实现为一张大尺寸图片创建缩略图的方法分享

本文实例讲述了C#实现为一张大尺寸图片创建缩略图的方法。分享给大家供大家参考。具体实现方法如下:

publicstaticBitmapCreateThumbnail(stringlcFilename,intlnWidth,intlnHeight) { System.Drawing.BitmapbmpOut=null; try { BitmaploBMP=newBitmap(lcFilename); ImageFormatloFormat=loBMP.RawFormat; decimallnRatio; intlnNewWidth=0; intlnNewHeight=0; //***Iftheimageissmallerthanathumbnailjustreturnit if(loBMP.Width<lnWidth&&loBMP.Height<lnHeight) returnloBMP; if(loBMP.Width>loBMP.Height) { lnRatio=(decimal)lnWidth/loBMP.Width; lnNewWidth=lnWidth; decimallnTemp=loBMP.Height*lnRatio; lnNewHeight=(int)lnTemp; } else { lnRatio=(decimal)lnHeight/loBMP.Height; lnNewHeight=lnHeight; decimallnTemp=loBMP.Width*lnRatio; lnNewWidth=(int)lnTemp; } bmpOut=newBitmap(lnNewWidth,lnNewHeight); Graphicsg=Graphics.FromImage(bmpOut); g.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.FillRectangle(Brushes.White,0,0,lnNewWidth,lnNewHeight); g.DrawImage(loBMP,0,0,lnNewWidth,lnNewHeight); loBMP.Dispose(); } catch { returnnull; } returnbmpOut; }

希望本文所述对大家的C#程序设计有所帮助。

您可能感兴趣的文章:C#生成高质量缩略图程序—终极算法C#添加图片水印类实现代码C#jpg缩略图函数代码.netc#gif动画如何添加图片水印实现思路及代码c#多图片上传并生成缩略图的实例代码c#生成图片缩略图的类(2种实现思路)c#利用Grahics进行图片裁剪c#生成高清缩略图的二个示例分享c#图片处理之图片裁剪成不规则图形C#使用GDI+创建缩略图实例C#获取视频某一帧的缩略图的方法C#简单生成缩略图的方法C#创建缩略图操作类实例C#图片处理3种高级应用

标签: 缩略图 图片 方法

C语言实现图的搜索算法示例

C++解析Json的方法详解【jsoncpp】

上述就是C#学习教程:C#实现为一张大尺寸图片创建缩略图的方法分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/906561.html

(0)
上一篇 2021年10月23日
下一篇 2021年10月23日

精彩推荐