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
}
查看全文
相关阅读:
Java实现各种内部排序算法
Java实现堆排序(大根堆)
Java对象的序列化和反序列化
Java实现链式存储的二叉查找树(递归方法)
337. House Robber III(包含I和II)
318. Maximum Product of Word Lengths
114. Flatten Binary Tree to Linked List
106. Construct Binary Tree from Inorder and Postorder Traversal
105. Construct Binary Tree from Preorder and Inorder Traversal
96. Unique Binary Search Trees(I 和 II)
原文地址:https://www.cnblogs.com/ghd258/p/270447.html
最新文章
AjaxFormSubmit使用demo
js子窗体、父窗体方法互调
Json.net对于导航属性的处理(解决对象循环引用)
T4模板
Android 水波纹点击效果(Ripple Effect)
Android Espresso(UI自动化测试)的搭建
Java与线程
Java虚拟机内存模型和volatile型变量
Android Fresco (Facebook开源的图片加载管理库)
Java方法参数传递
热门文章
Android 分Dex (MultiDex)
Java内存区域介绍
Java虚拟机的内存管理----垃圾收集器
Java虚拟机的内存管理
jdk1.8.0_45源码解读——LinkedList的实现
java.lang.System.arraycopy() 与java.util.Arrays.copyOf()的区别
jdk1.8.0_45源码解读——ArrayList的实现
Java中的容器类(List,Set,Map,Queue)
Java实现基于桶式排序思想和计数排序思想实现的基数排序
Linux Ubuntu下安装配置mysql
Copyright © 2011-2022 走看看