最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#實(shí)現(xiàn)為一張大尺寸圖片創(chuàng)建縮略圖的方法

 更新時(shí)間:2015年06月16日 12:12:22   作者:紅薯  
這篇文章主要介紹了C#實(shí)現(xiàn)為一張大尺寸圖片創(chuàng)建縮略圖的方法,涉及C#創(chuàng)建縮略圖的相關(guān)圖片操作技巧,需要的朋友可以參考下

本文實(shí)例講述了C#實(shí)現(xiàn)為一張大尺寸圖片創(chuàng)建縮略圖的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

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;
}

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

南宁市| 惠东县| 崇信县| 宜州市| 阳曲县| 昭苏县| 巴彦淖尔市| 武宁县| 会宁县| 广丰县| 晋江市| 东明县| 昌黎县| 车险| 崇左市| 远安县| 建德市| 太谷县| 隆化县| 衡阳市| 专栏| 横峰县| 合水县| 郧西县| 兴海县| 岳普湖县| 靖州| 嵊州市| 东乡族自治县| 伊通| 惠水县| 南陵县| 巴塘县| 林周县| 巴彦县| 竹山县| 丹江口市| 英吉沙县| 内丘县| 彭泽县| 义马市|