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
}
查看全文
相关阅读:
从汇编的角度看待const与#define
从汇编的角度看待变量类型与sizeof的机制
按字节对齐分析
堆内存和栈内存的探索
string源码实现分析
string源码分析 ——转载 http://blogs.360.cn/360cloud/2012/11/26/linux-gcc-stl-string-in-depth/
开始了
atoi函数的实现——面试
new与malloc的区别,以及内存分配浅析
[C]C语言中EOF是什么意思?
原文地址:https://www.cnblogs.com/ghd258/p/270447.html
最新文章
微信推送消息--发送模板消息
js使用正则表达式从url中获取参数值
mysql 启动报错--发现系统错误2,系统找不到指定的文件。
shiro缓存
微信支付(公众号支付APIJS、app支付)服务端统一下单接口java版
微信绑定用户服务端代码-根据code获取openId然后绑定用户
接口日志记录AOP实现-LogAspect
当spring 容器初始化完成后执行某个方法
对sssp项目搭建的补充,总错误处理。
spring4+mybatis3+maven
热门文章
windows7系统配置maven环境
MySQL查询分析器EXPLAIN或DESC
利用mycat实现mysql数据库读写分离
数据库中间件mycat简单入门
mysql5.7主从复制
mysql通过binlog日志来恢复数据
在centos6.5中安装mysql5.7
redis.conf详解
redis主从复制
从内存的角度观察 堆、栈、全局区(静态区)(static)、文字常量区、程序代码区
Copyright © 2011-2022 走看看