UIImage 压缩
来源:互联网 发布:网络戴帽子唱歌的女生 编辑:程序博客网 时间:2024/06/07 02:59
直接上代码。实际使用中可以根据需要调节图片size 和压缩比例compressionQuality
-(UIImage *)compressImage:(UIImage *)image{ float actualHeight = image.size.height; float actualWidth = image.size.width; float maxHeight = 600.0; float maxWidth = 800.0; float imgRatio = actualWidth/actualHeight; float maxRatio = maxWidth/maxHeight; float compressionQuality = 0.5;//50 percent compression if (actualHeight > maxHeight || actualWidth > maxWidth){ if(imgRatio < maxRatio){ //adjust width according to maxHeight imgRatio = maxHeight / actualHeight; actualWidth = imgRatio * actualWidth; actualHeight = maxHeight; } else if(imgRatio > maxRatio){ //adjust height according to maxWidth imgRatio = maxWidth / actualWidth; actualHeight = imgRatio * actualHeight; actualWidth = maxWidth; } else{ actualHeight = maxHeight; actualWidth = maxWidth; } } CGRect rect = CGRectMake(0.0, 0.0, actualWidth, actualHeight); UIGraphicsBeginImageContext(rect.size); [image drawInRect:rect]; UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); NSData *imageData = UIImageJPEGRepresentation(img, compressionQuality); UIGraphicsEndImageContext(); return [UIImage imageWithData:imageData];}
0 0
- UIImage 压缩
- UIImage 压缩
- UIImage 压缩
- UIImage 压缩
- IOS_压缩图片UIImage
- UIImage图片压缩和截取
- iOS 图片压缩UIImage方法扩展
- iOS 图片压缩UIImage方法扩展
- iOS 图片压缩UIImage方法扩展
- iOS 图片压缩UIImage方法扩展
- iOS 图片压缩UIImage方法扩展
- iOS 关于UIImage的压缩问题
- iOS 图片压缩UIImage方法扩展
- uiimage
- UIImage
- UIImage
- UIImage
- UIImage
- createjs初学-关于cache
- android自定义View组件封装jar包
- Android动画
- linux学习笔记----文件处理命令--head= 显示文件前几行内容
- win8和win7下解决php5.3和5.4、5.5等不能加载php_curl.dll的终极解决办法
- UIImage 压缩
- JNDI 命名和目录操作
- Linux集群系列01-LVS_NAT模型配置
- IT菜鸟四年学习感悟
- 我是如何构建一个持续发展的项目
- 黑马程序员--java技术blog---第九篇:网络编程(2)
- 传值还是传引用
- 特征工程 vs. 特征提取
- ubuntu配置cron