国产探花免费观看_亚洲丰满少妇自慰呻吟_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;
}
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 双流县| 渝北区| 靖州| 惠水县| 林甸县| 疏附县| 汤原县| 建平县| 汕头市| 横山县| 朝阳县| 阿克苏市| 桐乡市| 行唐县| 来宾市| 长乐市| 云和县| 青川县| 教育| 陆河县| 岢岚县| 武义县| 井冈山市| 柞水县| 盐源县| 竹北市| 文化| 同江市| 连山| 大方县| 镇江市| 海原县| 丰县| 穆棱市| 思茅市| 赞皇县| 分宜县| 桓台县| 修水县| 如东县| 沂水县|