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

c#生成縮略圖不失真的方法實(shí)例分享

 更新時(shí)間:2013年12月26日 16:41:27   作者:  
使用.net的方法GetThumbnailImage生成的縮略圖失真嚴(yán)重,這里推薦一種不失真生成縮略圖的方法

復(fù)制代碼 代碼如下:

/// <summary>
/// 獲得縮微圖
/// </summary>
/// <returns></returns>
  public bool GetThumbImg()
{
try
{
string imgpath; //原始路徑
     if(imgsourceurl.IndexOf("\",0)<0) //使用的是相對(duì)路徑
     {
imgpath = HttpContext.Current.Server.MapPath(imgsourceurl); //轉(zhuǎn)化為物理路徑
     }
else
{
imgpath=imgsourceurl;
}
System.Drawing.Image sourceImage = System.Drawing.Image.FromFile(imgpath);
int width = sourceImage.Width;
int height = sourceImage.Height;
if(thumbwidth <= 0)
{
thumbwidth = 120;
}
if(thumbwidth >= width)
{
return false;
}
else
{
(thumbwidth,thHeight*thumbwidth/thWidth,null,IntPtr.Zero);
Image imgThumb=new System.Drawing.Bitmap(thumbwidth,height*thumbwidth/width);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(imgThumb);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(sourceImage, new Rectangle(0, 0, thumbwidth,height*thumbwidth/width), 0, 0, width, height, GraphicsUnit.Pixel);
string thumbpath="";
sourceImage.Dispose();
if(thumburl=="")
{
thumbpath=imgpath;
}
if(thumbpath.IndexOf("\",0)<0)//使用的是相對(duì)路徑
      {
thumbpath=HttpContext.Current.Server.MapPath(thumburl);//轉(zhuǎn)化為物理路徑
      }
imgThumb.Save(thumbpath,ImageFormat.Jpeg);
imgThumb.Dispose();
return true;
}
}
catch
{
throw;
}
}

相關(guān)文章

最新評(píng)論

乾安县| 涡阳县| 苗栗县| 莱西市| 招远市| 河南省| 读书| 双峰县| 灯塔市| 白水县| 威远县| 洮南市| 得荣县| 太仆寺旗| 兴安盟| 清水河县| 随州市| 横山县| 桂东县| 油尖旺区| 庆城县| 青州市| 南充市| 改则县| 鸡东县| 利辛县| 即墨市| 新乡市| 唐河县| 新郑市| 嘉祥县| 平舆县| 宝丰县| 宜章县| 仙桃市| 成都市| 华容县| 衡东县| 聊城市| 齐齐哈尔市| 乡城县|