Search code examples
iphoneobjective-cuiimagensdatauiimagejpegrepresentation

Inverse of NSData to UIImage conversion?


In an iPhone app I load a JPG image off a server using a standard HTTP request. The data comes back as NSData, which I can convert into a UIImage using the [UIImage imageWithData:responseData] function. My question is, can I convert the UIImage representation of my image back to the same NSData that it originated from? I know about the UIImageJPEGRepresentation() function, but I tried that with a compressionQuality of 1 and that gave me something different than the original NSData.


Solution

  • I think (guess, actually) your issue is probably because a UIImage is not stored in JPEG format internally. Because of the way JPEG compression works, it is unlikely that the conversion back to JPEG could give you the exact same data. Is there any reason why you can't keep the original NSData hanging around?