UIImageJPEGRepresentation 使用中存在的问题

来源:互联网 发布:我与网络强国 编辑:程序博客网 时间:2024/06/07 18:59

iOS上有两种转化图片的的简单方法:1丶UIImageJPEGRepresentation(<#UIImage * _Nonnull image#>, <#CGFloat compressionQuality#>)参数1:图片,参数2:压缩系数2丶UIImagePNGRepresentation(<#UIImage * _Nonnull image#>)参数:图片UIImageJPEGRepresentation 压缩后图片较小图片质量也无较大差异:UIImagePNGRepresentation 压缩图片的图片较大;日常工作中推荐使用的是UIImageJPEGRepresentation图压缩后节省内存,减少避免图片过多照成的卡顿现象。当然如果对图片画质有极高的要求的话,还是使用UIImagePNGRepresentation。使用UIImageJPEGRepresentation遇到的问题:///< NSData *data = UIImageJPEGRepresentation(image, 1);偶然发现使用UIImageJPEGRepresentation 一些无背景的白色图案经过压缩之后会变成白色背景无图案的图片,因为像素低,再经压缩后,就会导致图片失真, 成为白底无图案的图片(这种情况应该不常见,但确实存在);后只能使用UIImagePNGRepresentation用原图展示,当然这不是最好的方法。