What should compressionQuality be when using UIImageJPEGRepresentation?

廉价感情. 提交于 2019-12-03 01:24:49

This is an old question and you've probably worked this out for yourself, but if anyone's still interested, this might help.

(I'm not a JPEG expert)

UIImageJPEGRepresentation isn't taking into consideration how the image may have been compressed in the past, it's just compressing the image that it has at the time.

You mention a photo that's "from the user's library". The user could have any image in their library, compressed at any compressionQuality.

To try to keep the image at the same file size, you'd need to know how it was originally saved, and even if you use the same compressionQuality, you will likely result in a different file size because the data that's being compressed is different.

As for using a compressionQuality of 0.9 for saving images, it depends on how much you value the quality of your image versus how much you space you want to use. 0.7 seems to be often suggested as a good balance.

I'm not sure how much the iOS camera app compresses the image (if at all) and I'm not sure that it is guaranteed to be the best possible quality. If it is using 0.9, you could always create an app that takes a photo and compresses it less before saving.

I hope that helps.

You can convert image in PNG representation for original image quality.

UIImagePNGRepresentation(image)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!