国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#實現為一張大尺寸圖片創建縮略圖的方法

2020-01-24 01:43:10
字體:
來源:轉載
供稿:網友

本文實例講述了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#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 来宾市| 晋城| 嘉义市| 绿春县| 阜康市| 德钦县| 淮滨县| 稷山县| 张家港市| 鹤山市| 开化县| 郓城县| 郎溪县| 宁河县| 萨迦县| 平顺县| 岐山县| 乌兰察布市| 奉化市| 新竹市| 嘉鱼县| 尼木县| 舟曲县| 布拖县| 观塘区| 卢龙县| 交城县| 望都县| 车险| 和硕县| 黄龙县| 五河县| 通化县| 商河县| 丰镇市| 霍城县| 呼伦贝尔市| 安徽省| 安徽省| 额尔古纳市| 额尔古纳市|