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
}
查看全文
相关阅读:
Live2D 看板娘
Live2D 看板娘
Live2D 看板娘
Live2D 看板娘
Live2D 看板娘
Live2D 看板娘
Live2D 看板娘
Live2D 看板娘
Live2D 看板娘
[转载]MySQL5.5 配置文件 my.ini 1067错误
原文地址:https://www.cnblogs.com/ghd258/p/270447.html
最新文章
生产者消费者问题--BlockingQueue
生产者消费者问题--lock
生产者消费者问题--synchronized
使用Redis作为分布式锁的一些注意点
Java注解demo
new一个有父类的对象时各代码块的执行顺序问题
JAVA字符串格式化-String.format()的使用
线程安全的单例-懒汉
java string split 怎么保留尾部空字符串
scrapy入门例子
热门文章
itemgetter和groupby
记一次升级Ubuntu内核
处理序列的几个小技巧:保持原序去重,命名切片以及Counter类
关于字典的几个类--defaultdict,OrderedDict, zip()
使用deque模块固定队列长度,用headq模块来查找最大或最小的N个元素以及实现一个优先级排序的队列
把序列中的N个元素赋值给多个变量
shell实战之case语句的选择提示
SSH端口转发
Redis存储
Live2D 看板娘
Copyright © 2011-2022 走看看