IOS开发 如果图片太大的缩小算法,通用多种情况
2015-03-03 11:33
302 查看
- (CGSize)getSizeWithHeight:(CGFloat)height width:(CGFloat)width
{
CGSize size = {0,0};
CGFloat fHeight = [UIScreen
mainScreen].bounds.size.height;
CGFloat fWidth = [UIScreen
mainScreen].bounds.size.width;
if (height < fHeight && width < fWidth)
{
size.height = height;
size.width = width;
}
else
{
if (height >= fHeight && width <= fWidth)
{
CGFloat mult = fHeight/height;
size.height = fHeight;
size.width = width*mult;
}
else if (height <= fHeight && width >= fWidth)
{
CGFloat mult = fWidth/width;
size.height = height*mult;
size.width = fWidth;
}
else if (height >= fHeight && width >= fWidth)
{
CGFloat multW = fWidth/width;
CGFloat multH = fHeight/height;
if (multW <= multH)
{
size.height = height*multW;
size.width = fWidth;
}
else
{
size.width = width*multH;
size.height = fHeight;
}
}
}
return size;
}
{
CGSize size = {0,0};
CGFloat fHeight = [UIScreen
mainScreen].bounds.size.height;
CGFloat fWidth = [UIScreen
mainScreen].bounds.size.width;
if (height < fHeight && width < fWidth)
{
size.height = height;
size.width = width;
}
else
{
if (height >= fHeight && width <= fWidth)
{
CGFloat mult = fHeight/height;
size.height = fHeight;
size.width = width*mult;
}
else if (height <= fHeight && width >= fWidth)
{
CGFloat mult = fWidth/width;
size.height = height*mult;
size.width = fWidth;
}
else if (height >= fHeight && width >= fWidth)
{
CGFloat multW = fWidth/width;
CGFloat multH = fHeight/height;
if (multW <= multH)
{
size.height = height*multW;
size.width = fWidth;
}
else
{
size.width = width*multH;
size.height = fHeight;
}
}
}
return size;
}
相关文章推荐
- iOS开发 图片缩小 裁剪 虚化
- iOS开发 UI高级 图片放大缩小的实现
- iOS开发中,点击放大、缩小图片方法举例
- iOS开发小技巧--巧用ImageView中的mode(解决图片被拉伸的情况)
- iOS开发图片纯色填充(两种方式)和缩小图片
- 移动应用开发(IOS/android等)中一个通用的图片缓存方案讲解
- iOS开发之制作@2x和缩小图片
- iOS开发中压缩图片的质量以及缩小图片尺寸
- iOS开发~SDWebImage是如何做到Url不变的情况下,更新图片内容的
- iOS开发图片美白处理,图像处理,,磨皮,马赛克基于UIKit下自写算法
- iOS开发~SDWebImage是如何做到Url不变的情况下,更新图片内容的
- iOS开发——手势识别器(用手势实现图片旋转和缩小放大)
- IOS开发笔记-02 图片浏览&amp;Tom 猫-01.放大缩小 02.首尾式动画 03.位移形变
- 移动应用开发(IOS/android等)中一个通用的图片缓存方案讲解(附流程图)
- ios开发使用UIWebView显示多种文档
- ios开发之创建图片,为何不用alloc
- ios开发使用UIWebView显示多种文档
- IOS开发之xcode 4设置应用程序图标及加载图片
- IOS开发之UIButton同时设置图片文字以及出发按钮时文字图片的切换
- IOS开发之——裁剪图片