zoukankan
html css js c++ java
Asp.Net中图片大小的缩放
在Asp.Net中显示图片的时候,如果给定一个固定大小的容器,如<Table>,图片的大小如何根据容器的大小进行比例缩放呢。以下是一个比较简单的函数,根据图片的宽高比例进行计算,缩放后保持比例不变。
//
ViewSize 外框大小
//
ImageSize 图片的实际大小
public
Size Resize(Size ViewSize, Size ImageSize)
{
Size MySize
=
new
Size();
if
(ViewSize.Width
>
ViewSize.Height)
//
宽大于高
{
if
(ImageSize.Width
>
ImageSize.Height)
//
按比例
{
float
scale
=
ImageSize.Height
/
(
float
)ImageSize.Width;
if
(ViewSize.Height
/
(
float
)ViewSize.Width
<
scale)
{
MySize.Height
=
ViewSize.Height;
MySize.Width
=
(
int
)(ViewSize.Height
/
scale);
}
else
{
MySize.Width
=
ViewSize.Width;
MySize.Height
=
(
int
)(ViewSize.Width
*
scale);
}
}
else
if
(ImageSize.Height
>
ImageSize.Width)
//
非比例
{
float
scale
=
ImageSize.Width
/
(
float
)ImageSize.Height;
MySize.Height
=
ViewSize.Height;
MySize.Width
=
(
int
)(ViewSize.Height
*
scale);
}
else
//
正方
{
MySize.Height
=
ViewSize.Height;
MySize.Width
=
ViewSize.Height;
}
}
else
if
(ViewSize.Width
<
ViewSize.Height)
//
高大于宽
{
if
(ImageSize.Width
<
ImageSize.Height)
//
按比例
{
float
scale
=
ImageSize.Width
/
(
float
)ImageSize.Height;
if
(ViewSize.Width
/
(
float
)ViewSize.Height
<
scale)
{
MySize.Width
=
ViewSize.Width;
MySize.Height
=
(
int
)(ViewSize.Width
/
scale);
}
else
{
MySize.Height
=
ViewSize.Height;
MySize.Width
=
(
int
)(ViewSize.Height
*
scale);
}
}
else
if
(ImageSize.Height
<
ImageSize.Width)
//
非比例
{
float
scale
=
ImageSize.Height
/
(
float
)ImageSize.Width;
MySize.Width
=
ViewSize.Width;
MySize.Height
=
(
int
)(ViewSize.Width
*
scale);
}
else
//
正方
{
MySize.Height
=
ViewSize.Width;
MySize.Width
=
ViewSize.Width;
}
}
else
//
正方
{
if
(ImageSize.Width
>
ImageSize.Height)
//
宽大于高
{
float
scale
=
ImageSize.Height
/
(
float
)ImageSize.Width;
MySize.Width
=
ViewSize.Width;
MySize.Height
=
(
int
)(ViewSize.Width
*
scale);
}
else
if
(ImageSize.Width
<
ImageSize.Height)
//
高大于宽
{
float
scale
=
ImageSize.Width
/
(
float
)ImageSize.Height;
MySize.Height
=
ViewSize.Height;
MySize.Width
=
(
int
)(ViewSize.Height
*
scale);
}
else
//
正方
{
MySize.Height
=
ViewSize.Height;
MySize.Width
=
ViewSize.Height;
}
}
return
MySize;
}
查看全文
相关阅读:
PLSQL13
01.Spring引入
验证码重构
短信验证码登录思路
记住我 token保存到数据库
图形验证码及其重构
个性化用户认证流程
01.Spring Security初识,表单认证
堆和栈的区别
系统分析与设计第二次作业
原文地址:https://www.cnblogs.com/faib/p/754191.html
最新文章
priority_queue(优先队列)使用方法
并查集 | 1107
BST | 1064 完全二叉搜索树
BST | 1043 BST树与镜像BST树的判断
搜索法 | 1091bfs搜索:三维bfs
搜索法 | 1103 dfs搜索:符合条件的多项式
最短路径 | 1072 全源最短路径+细节
最短路径 | 1087 三重标尺+记录最短路径条数
AJAX数据传输(原生js)
面试问题
热门文章
bind() 方法
addEventListener和onclick的区别
Webpack与Gulp、Grunt区别
事件委托
ready vs onload
什么是闭包
GET/POST区别
AJAX数据传输
mac配置gradle环境变量
02.spring的依赖注入、配置ApplicationContext
Copyright © 2011-2022 走看看