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
}
查看全文
相关阅读:
虚树学习笔记
CF487E Tourists
[HNOI/AHOI2018]毒瘤
[HEOI2014]大工程
hive初始化元数据报错
layui简单的两个页面
springboot配置swagger信息入门2
spark连接hive出现错误,javax.jdo.JDODataStoreException: Required table missing : "`DBS`" in Catalog "" Schema ""
springboot整合shiro关于任务入门3
Flink部署Standalone模式
原文地址:https://www.cnblogs.com/ghd258/p/270447.html
最新文章
SilverlightVisifire图表使用示例发布时空白页面的解决办法
将PDF转为TXT文本格式提取中文
【转载】让你的iPhone app在iOS4中支持最基本的多任务
[转]由init、loadView、viewDidLoad、viewDidUnload、dealloc的关系说起
转 专访Rust——由Mozilla开发的系统编程语言
转 采访:Go语言编程
转 哪种编程语言更好?真的不重要
转 看透面向对象的复用技术
转 Panel: Answers from Microsoft Developers Who Built WinRT
转 面向对象编程从骨子里就有问题
热门文章
转 =的两边
转 面向对象不是计算机编程的基本原子
Windows8 Runtime Component一些总结
转 Go语言的崛起?
[SDOI2011]消耗战
CF613D Kingdom and its Cities
CF639F Bear and Chemistry
[HNOI2014]世界树
LOJ#3077. 「2019 集训队互测 Day 4」绝目编诗
线性基学习笔记
Copyright © 2011-2022 走看看