IOS 图片压缩保存
来源:互联网 发布:sicp 知乎 编辑:程序博客网 时间:2024/05/23 13:40
创建一个UIImage+Category用于压缩图片处理/** * @brief 压缩照片 * @parma img:目标图片 * @parma newSize:压缩至目标尺寸 */-(UIImage *)compressImageWithImage:(UIImage *)img scaleToSize:(CGSize)newsize{ UIGraphicsBeginImageContext(newsize);// [img drawInRect:CGRectMake(0, 0,newsize.width, newsize.height)]; [img drawInRect:CGRectMake(0, 0,newsize.width + 1, newsize.height) blendMode:kCGBlendModeLuminosity alpha:1]; UIImage *resImge = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return resImge;}/** * @brief 保存至相册 * @parma newSize:压缩至目标尺寸 */-(void)saveImageToAlbumWithImage:(UIImage *)image{ UIImageWriteToSavedPhotosAlbum(image, nil, @selector(saveSuccess), nil);}
在需要压缩图片的地方使用:
//压缩图片- (UIImage *) saveImage:(UIImage *)currentImage{ NSData *imgaData = UIImageJPEGRepresentation(currentImage, 1); if (imgaData == nil) { return nil; } float imageSize = imgaData.length/1024.0; if(imageSize < 300) { return currentImage; }else{ //300为300k得到需要缩小的倍数关系传入宽高比进项压缩 CGFloat imgWidth = currentImage.size.width/sqrtf(imageSize/300); CGFloat imgHeight = currentImage.size.height/sqrtf(imageSize/300); UIImage *resImage = [currentImage compressImageWithImage:currentImage scaleToSize:CGSizeMake(imgWidth, imgHeight)]; return resImage; }}
0 0
- IOS 图片压缩保存
- iOS 中图片的压缩以及保存
- 压缩图片,保存图片
- 图片压缩保存
- iOS 图片压缩以及保存到doucument的方法
- [iOS]图片压缩&保存View为内容Img
- 上传图片进行压缩保存
- 图片压缩保存读取操作
- IOS 图片压缩
- ios--图片压缩/缩放
- IOS 图片压缩
- ios图片压缩
- IOS 图片压缩
- iOS 图片压缩
- IOS 图片压缩
- ios 图片压缩
- ios 图片压缩
- ios 图片压缩
- hibernate03 关系操作 多对多
- 集成趣拍SDK的那些事
- hive建表语法中的分隔符设定
- Jedis 实现发布订阅
- windows下mysql忘记root密码的解决办法
- IOS 图片压缩保存
- maven时报错Dmaven.multiModuleProjectDirectory system propery is not set
- js打印功能
- 使CMD.exe支持UNC路径
- for_each
- XCode 中使用-Objc和-all_load的作用
- Centos修炼----->Centos7办公环境打造(No3 Office安装)
- 一个关于NGUI的点击和按键响应的Bug
- JAVA工程师成神之路--基础篇(一)目录