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
}
查看全文
相关阅读:
管理信息系统的开发与管理
加载静态文件,父模板的继承和扩展(2017.11.3)
开始Flask项目(2017.11.3)
夜间模式的开启与关闭,父模板的制作(2017.11.2)
完成登录与注册页面的前端(2017.10.31)
JavaScript 基础,登录验证(2017.10.24)
CSS实例:图片导航块(2017.10.20)
导航,头部,CSS基础 (10.18)
ASCII表
RSA加密算法
原文地址:https://www.cnblogs.com/ghd258/p/270447.html
最新文章
[PKUWC2018]Minimax 题解
FJOI2020 游记
CF208E Blood Cousins 题解
CF1349A Orac and LCM 题解
CF1270B Interesting Subarray 题解
CF1271C Shawarma Tent 题解
[CSP-S2019]树上的数 题解
[CSP-S2019]树的重心 题解
作为一个Tester,你在客户环境能保证质量吗?
上线前测试的bug,要不要处理,跟版本的关系
热门文章
应多站在客户角度来测试
“天使项目”,高风险如何应对?!
需求环节测试是否应该介入
小程序-需求评审阶段介入测试
项目团队测试改进&产品测试方法的思考和改进
项目究竟是本地测试通过后再部署,还是也可以生产环境测试
小程序“回馈模块”第一轮测试结束
小程序“回馈模块”测试接近尾声
通过用户模型,对数据库进行增删改查操作(2017.11.15)
连接mysql数据库,创建用户模型
Copyright © 2011-2022 走看看