Asp.Net中图片大小的缩放
来源:互联网 发布:mac综艺体字体下载 编辑:程序博客网 时间:2024/05/29 13:34
在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;
}
- Asp.Net中图片大小的缩放
- ASP.NET C# 按原图片大小缩放生成缩略图
- 学习 ------ ASP.NET C# 按原图片大小缩放生成缩略图
- ASP.NET C# 按原图片大小缩放生成缩略图
- Asp.net获取上传图片大小的尺寸!
- ASP.NET C# 按原图片大小等比例缩放生成缩略图
- .net中判断图片大小
- ASP.NET实现自适应图片大小的弹出窗口
- ASP.NET实现自适应图片大小的弹出窗口(转)
- ASP.NET实现自适应图片大小的弹出窗口
- ASP.NET实现自适应图片大小的弹出窗口
- ASP.NET实现自适应图片大小的弹出窗口
- ASP.NET实现自适应图片大小的弹出窗口
- ASP.NET实现自适应图片大小的弹出窗口
- ASP.NET实现自适应图片大小的弹出窗口
- opencv 基本操作-图片大小的缩放
- kindeditor中(文件的上传)与(图片上传缩放),整合(asp.net)
- 改变图片大小、无级缩放图片大小
- 使用three.js画一个三角形
- SwipeRefreshLayout简单使用
- C# 将数据生成excel并储存
- 码农如何克服“职业病”
- 国内SDK开发包下载
- Asp.Net中图片大小的缩放
- 程序员分类
- Linux上编译hadoop-2.7.1的libhdfs.so和libhdfs.a
- Spring集成Quartz定时任务框架介绍和Cron表达式详解
- 安卓错误积累(1)
- mysql伪序列实现-最简单方法
- sql 字符串加1
- 钻一钻Tomcat 之 Tomcat管理员账号密码(Ⅴ)
- java高并发,如何解决,什么方式解决