C#实现为一张大尺寸图片创建缩略图的方法
程序员文章站
2023-11-27 13:34:58
本文实例讲述了c#实现为一张大尺寸图片创建缩略图的方法。分享给大家供大家参考。具体实现方法如下:
public static bitmap createthumb...
本文实例讲述了c#实现为一张大尺寸图片创建缩略图的方法。分享给大家供大家参考。具体实现方法如下:
public static bitmap createthumbnail(string lcfilename, int lnwidth, int lnheight) { system.drawing.bitmap bmpout = null; try { bitmap lobmp = new bitmap(lcfilename); imageformat loformat = lobmp.rawformat; decimal lnratio; int lnnewwidth = 0; int lnnewheight = 0; //*** if the image is smaller than a thumbnail just return it if (lobmp.width < lnwidth && lobmp.height < lnheight) return lobmp; if (lobmp.width > lobmp.height) { lnratio = (decimal)lnwidth / lobmp.width; lnnewwidth = lnwidth; decimal lntemp = lobmp.height * lnratio; lnnewheight = (int)lntemp; } else { lnratio = (decimal)lnheight / lobmp.height; lnnewheight = lnheight; decimal lntemp = lobmp.width * lnratio; lnnewwidth = (int)lntemp; } bmpout = new bitmap(lnnewwidth, lnnewheight); graphics g = 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 { return null; } return bmpout; }
希望本文所述对大家的c#程序设计有所帮助。