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ì)有所幫助。
您可能感興趣的文章:
- C# 生成高質(zhì)量縮略圖程序—終極算法
- C# 添加圖片水印類實(shí)現(xiàn)代碼
- C# jpg縮略圖函數(shù)代碼
- .net c# gif動(dòng)畫如何添加圖片水印實(shí)現(xiàn)思路及代碼
- c#多圖片上傳并生成縮略圖的實(shí)例代碼
- c#生成圖片縮略圖的類(2種實(shí)現(xiàn)思路)
- c#利用Grahics進(jìn)行圖片裁剪
- c#生成高清縮略圖的二個(gè)示例分享
- c#圖片處理之圖片裁剪成不規(guī)則圖形
- C#使用GDI+創(chuàng)建縮略圖實(shí)例
- C#獲取視頻某一幀的縮略圖的方法
- C#簡(jiǎn)單生成縮略圖的方法
- C#創(chuàng)建縮略圖操作類實(shí)例
- C#圖片處理3種高級(jí)應(yīng)用
相關(guān)文章
c#循環(huán)中產(chǎn)生偽隨機(jī)數(shù)
在循環(huán)中產(chǎn)生多個(gè)隨機(jī)數(shù),容易出現(xiàn)連續(xù)相同的數(shù)據(jù),最終的多個(gè)隨機(jī)數(shù)并不隨機(jī),而是帶有某種規(guī)律性。2010-06-06
unity 如何判斷鼠標(biāo)是否在哪個(gè)UI上(兩種方法)
這篇文章主要介紹了unity 判斷鼠標(biāo)是否在哪個(gè)UI上的兩種實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2021-04-04
Unity3D實(shí)現(xiàn)待機(jī)狀態(tài)圖片循環(huán)淡入淡出
這篇文章主要為大家詳細(xì)介紹了Unity3D實(shí)現(xiàn)待機(jī)狀態(tài)圖片循環(huán)淡入淡出,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-04-04

