zoukankan
html css js c++ java
按比例缩放图片
1
/**/
///
<summary>
2
///
按比例缩放图片
3
///
</summary>
4
///
<param name="imgUrl">
图片的路径
</param>
5
///
<param name="imgHeight">
图片的高度
</param>
6
///
<param name="imgWidth">
图片的宽度
</param>
7
///
<returns></returns>
8
public
static
string
GetImageSize(
string
imgUrl,
int
imgHeight,
int
imgWidth)
9
{
10
string
fileName
=
System.Web.HttpContext.Current.Server.MapPath(imgUrl);
11
string
strResult
=
string
.Empty;
12
if
(System.IO.File.Exists(fileName)
&&
imgHeight
!=
0
&&
imgWidth
!=
0
)
13
{
14
decimal
desWidth;
decimal
desHeight;
//
目标宽高
15
System.Drawing.Image objImage
=
System.Drawing.Image.FromFile(fileName);
16
decimal
radioAct
=
(
decimal
)objImage.Width
/
(
decimal
)objImage.Height;
//
原始图片的宽高比
17
decimal
radioLoc
=
(
decimal
)imgWidth
/
(
decimal
)imgHeight;
//
图片位的宽高比
18
if
(radioAct
>
radioLoc)
//
原始图片比图片位宽
19
{
20
decimal
dcmZoom
=
(
decimal
)imgWidth
/
(
decimal
)objImage.Width;
21
desHeight
=
objImage.Height
*
dcmZoom;
22
desWidth
=
imgWidth;
23
}
24
else
25
{
26
decimal
dcmZoom
=
(
decimal
)imgHeight
/
(
decimal
)objImage.Height;
27
desWidth
=
objImage.Width
*
dcmZoom;
28
desHeight
=
imgHeight;
29
}
30
objImage.Dispose();
//
释放资源
31
strResult
=
"
width=\
""
+ Convert.ToString((int)desWidth) +
"
\
"
height=\
""
32
+
Convert.ToString((
int
)desHeight)
+
"
\
"
"
;
33
}
34
return
strResult;
35
}
查看全文
相关阅读:
51nod1376 最长递增子序列的数量
51nod1201 整数划分
51nod1202 子序列个数
51nod 博弈论水题
51nod1052 最大M子段和
51nod1678 lyk与gcd
51nod1262 扔球
BZOJ2763, 最短路
吃西瓜 最大子矩阵 三维的。 rqnoj93
noip2015 信息传递 强连通块
原文地址:https://www.cnblogs.com/ghd258/p/270447.html
最新文章
[BZOJ] 1609: [Usaco2008 Feb]Eating Together麻烦的聚餐
[BZOJ] 1610: [Usaco2008 Feb]Line连线游戏
[Codevs] 2492 上帝造题的七分钟2
树剖+线段树||树链剖分||BZOJ2238||Mst
树剖+线段树||树链剖分||BZOJ1984||Luogu4315||月下“毛景树”
树剖||树链剖分||线段树||BZOJ4034||Luogu3178||[HAOI2015]树上操作
分块+莫队||BZOJ3339||BZOJ3585||Luogu4137||Rmq Problem / mex
NOIP2018旅游记
BZOJ2744: [HEOI2012]朋友圈
BZOJ1923: [Sdoi2010]外星千足虫
热门文章
BZOJ1922: [Sdoi2010]大陆争霸
BZOJ3237: [Ahoi2013]连通图
BZOJ2001: [Hnoi2010]City 城市建设
BZOJ2115: [Wc2011] Xor
BZOJ3139: [Hnoi2013]比赛
BZOJ1135: [POI2009]Lyz
BZOJ2086: [Poi2010]Blocks
51nod1379 索函数
51nod1199 Money out of Thin Air
51nod1294 修改数组
Copyright © 2011-2022 走看看