知識
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價值,我們在追求其視覺表現(xiàn)的同時,更側(cè)重于功能的便捷,營銷的便利,運營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序為后期升級提供便捷的支持!
C# 生成縮略圖方法
發(fā)表時間:2021-3-19
發(fā)布人:葵宇科技
瀏覽次數(shù):56
拿記事本寫的,沒有調(diào)試,大概就是這么個原理,參考參考得了~
可以按寬度,高度縮放及指定高寬裁剪
private void MakeThumbnail(string sourcePath, string newPath, int width, int height)
{
System.Drawing.Image ig = System.Drawing.Image.FromFile(sourcePath);
int towidth = width;
int toheight = height;
int x = 0;
int y = 0;
int ow = ig.Width;
int oh = ig.Height;
if (height == 0)
{
toheight = oh * width / ow;
}
else if (width == 0)
{
towidth = ow * height / oh;
}
else
{
if ((double)ig.Width / (double)ig.Height > (double)towidth / (double)toheight)
{
oh = ig.Height;
ow = ig.Height * towidth / toheight;
y = 0;
x = (ig.Width - ow) / 2;
}
else
{
ow = ig.Width;
oh = ig.Width * height / towidth;
x = 0;
y = (ig.Height - oh) / 2;
}
}
System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.Clear(System.Drawing.Color.Transparent);
g.DrawImage(ig, new System.Drawing.Rectangle(0, 0, towidth, toheight), new System.Drawing.Rectangle(x, y, ow, oh), System.Drawing.GraphicsUnit.Pixel);
try
{
bitmap.Save(newPath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{
throw ex;
}
finally
{
ig.Dispose();
bitmap.Dispose();
g.Dispose();
}
}
相關(guān)案例查看更多
相關(guān)閱讀
- 報廢車拆解軟件
- 網(wǎng)站收錄
- 二叉樹
- 云南網(wǎng)站建設(shè)方案 doc
- 手機網(wǎng)站建設(shè)
- 國內(nèi)知名網(wǎng)站建設(shè)公司排名
- 網(wǎng)站制作哪家好
- 網(wǎng)絡(luò)公司
- 麗江小程序開發(fā)
- 大理小程序開發(fā)
- 做小程序被騙
- 小程序開發(fā)排名前十名
- 云南做百度小程序的公司
- 制作一個小程序
- 云南網(wǎng)站建設(shè)百度
- 云南建設(shè)廳網(wǎng)站
- 云南網(wǎng)站建設(shè)快速優(yōu)化
- 云南網(wǎng)絡(luò)推廣
- web開發(fā)技術(shù)
- 云南省城鄉(xiāng)建設(shè)廳網(wǎng)站
- flex
- 微信分銷
- 霸屏推廣
- 云南科技公司
- 報廢車回收管理軟件
- 云南建站公司
- APP
- 昆明網(wǎng)站設(shè)計
- 用戶登錄
- 報廢車管理系統(tǒng)