最新国产好看的视频,伊人天堂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)論

喀喇| 鄂伦春自治旗| 三门峡市| 大悟县| 洪雅县| 永昌县| 新源县| 上饶县| 托克托县| 胶南市| 板桥市| 松潘县| 乌鲁木齐县| 文安县| 澄江县| 密云县| 林州市| 东乡族自治县| 磐安县| 澎湖县| 齐齐哈尔市| 新巴尔虎右旗| 广河县| 石狮市| 长葛市| 秀山| 崇州市| 石城县| 阜阳市| 铜梁县| 邓州市| 中西区| 黄龙县| 南漳县| 安庆市| 乌拉特后旗| 神农架林区| 和田县| 宝丰县| 中阳县| 龙胜|