I can create UIImage from NSData using [UIImage imageWithData:] or [UIImage initWithData:] methods.
I wonder if I can get the NSData back from an existing UIImage? Something on the line of NSData *myData = [myImage getData];
NSData *imageData = UIImageJPEGRepresentation(image, 0.7); // 0.7 is JPG quality or
NSData *imageData = UIImagePNGRepresentation(image); Depending if you want your data in PNG format or JPG format.
When initialising a UIImage object with init(data: originalData), that originalData will be converted into raw data in some kind of internal format. These data can be retrieved later with
let rawData = myImage.cgImage?.dataProvider?.data as Data? However because the rawData is raw, it is going to be even larger than when using UIImagePNGRepresentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With