iOS开发之UIImage压缩处理

IOS中UIImage的数据量压缩有两种方式,一种是图片尺寸不变,降低图片分辨率,代码方法为:

//1.0为压缩系数,介于0~1之间。压缩系数越小,会大大降低图片清晰度

NSData *data = UIImageJPEGRepresentation(originalImage, 1.0);

另一种是按比例减小图片的尺寸,从而减小图片内存

按比例缩小图片尺寸的代码

-(UIImage )scaleImage:(UIImage )image toScale:(float)scaleSize
{
  UIGraphicsBeginImageContext(CGSizeMake(image.size.width
scaleSize,image.size.height
scaleSize));
  [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height *scaleSize)];
  UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  return scaledImage;
}


参考链接:https://www.jianshu.com/p/f77e71c8b4e3

posted @ 2020-12-10 14:25  kawerd  阅读(1157)  评论(0编辑  收藏  举报