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

首頁 > 編程 > C# > 正文

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

2024-09-07 17:05:28
字體:
來源:轉載
供稿:網友

代碼如下:
/// <summary>
/// 獲得縮微圖
/// </summary>
/// <returns></returns>
  public bool GetThumbImg()
{
try
{
string imgpath; //原始路徑
     if(imgsourceurl.IndexOf("/",0)<0) //使用的是相對路徑
     {
imgpath = HttpContext.Current.Server.MapPath(imgsourceurl); //轉化為物理路徑
     }
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)//使用的是相對路徑
      {
thumbpath=HttpContext.Current.Server.MapPath(thumburl);//轉化為物理路徑
      }
imgThumb.Save(thumbpath,ImageFormat.Jpeg);
imgThumb.Dispose();
return true;
}
}
catch
{
throw;
}
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 杭州市| 洪江市| 磐石市| 扶绥县| 灵丘县| 镇坪县| 唐河县| 五常市| 高州市| 南宫市| 团风县| 桑日县| 财经| 渭南市| 庆阳市| 宁安市| 扎兰屯市| 万全县| 林周县| 凤山县| 苍南县| 哈巴河县| 花莲市| 黔西| 绥棱县| 龙岩市| 鄂州市| 伊宁县| 左云县| 民丰县| 满洲里市| 泽普县| 阿克| 陇西县| 耒阳市| 新巴尔虎右旗| 赣榆县| 西昌市| 西乌珠穆沁旗| 简阳市| 张家界市|