佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > c#生成縮略圖不失真的方法實(shí)例分享

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

熱門標(biāo)簽:電商新玩法 科大訊飛語音識別系統(tǒng) 國美全國運(yùn)營中心 人工智能 網(wǎng)站排名優(yōu)化 百度AI接口 客戶服務(wù) 電銷業(yè)務(wù)

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

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

您可能感興趣的文章:
  • c#批量上傳圖片到服務(wù)器示例分享
  • C# 最齊全的上傳圖片方法
  • C#保存圖片到數(shù)據(jù)庫并讀取顯示圖片的方法
  • C#中按指定質(zhì)量保存圖片的實(shí)例代碼
  • C# 手動/自動保存圖片的實(shí)例代碼
  • c#讀取圖像保存到數(shù)據(jù)庫中(數(shù)據(jù)庫保存圖片)
  • C#給圖片添加水印完整實(shí)例
  • C#給圖片加水印的簡單實(shí)現(xiàn)方法
  • c#多圖片上傳并生成縮略圖的實(shí)例代碼
  • c#生成縮略圖的實(shí)現(xiàn)方法
  • C#實(shí)現(xiàn)的上傳圖片、保存圖片、加水印、生成縮略圖功能示例

標(biāo)簽:南平 益陽 POS機(jī) 攀枝花 咸寧 拉薩 廈門 棗莊

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《c#生成縮略圖不失真的方法實(shí)例分享》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    桃源县| 西盟| 曲沃县| 东兴市| 徐闻县| 孟连| 黄石市| 哈巴河县| 六安市| 新沂市| 乌苏市| 嘉义市| 祁东县| 灌阳县| 卫辉市| 旬邑县| 綦江县| 锦州市| 宁国市| 视频| 富源县| 台山市| 通化县| 绥芬河市| 唐河县| 泸州市| 丰县| 佳木斯市| 蓝山县| 沭阳县| 阳谷县| 和平县| 香港 | 咸丰县| 石河子市| 肥东县| 江川县| 焉耆| 长沙市| 双城市| 报价|