Convert UIImage to NSData increase the size of the original image
Originator: | igorferreiracastanheda | ||
Number: | rdar://FB5986565 | Date Originated: | 24/05/2016 |
Status: | Open | Resolved: | |
Product: | iOS SDK | Product Version: | |
Classification: | No Value | Reproducible: | Always |
Summary: When you convert a NSData to UIImage and back to NSData, the size of the image increases and the API do not provide a way to apply the same compression level of the original NSData, for some cases, even using the max compression of UIImageJPEGRepresentation. Steps to Reproduce: 1. Download an image from an URL or load it from the assets 2. Convert the NSData to UIImage 3. Convert the UIImage to NSData using UIImageJPEGRepresentation or UIImagePNGRepresentation Expected Results: The API should provide a method to convert the UIImage to NSData using the same compression of the original NSData Actual Results: The NSData result of the conversion is always bigger than the original NSData. For some images, the compression level on UIImageJPEGRepresentation may result on a data with smaller size or close to the original size, but the process to achieve it losing quality as less as possible is not simple. Notes: It can be seen using the example provided. That results on the follow: Original data: 16456 b UIImageJPEGRepresentation: - JPEG compressionQuality 1.0 image: 56647 b - JPEG compressionQuality 0.0 image: 24628 b UIImagePNGRepresentation - PNG image: 53419 b CGImageDestinationAddImage kUTTypeJPEG - CF JPEG compressionQuality 1.0 image: 56647 b - CF JPEG compressionQuality 0.0 image: 24628 b
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!