How to Get UIImage from a 'Base64String' f

2019-02-20 01:17发布

问题:

In my application, I receive the image data from the server in a XML file. This data is of an image( .jpeg or .png or .tiff etc) which the server, converts into 'Base64String' format bytes to send to my application through the XML file. At my application side, the application stores these bytes, in the form of 'NSData' into a database. Now, my application has to retrieve and show up the image at the later part. But I haven't been able to figure out how to get the UIImage from this 'Base64String' format raw image data? Kindly guide me in this regard, since I'm a 'just-in' developer in the world of iPhone app development.

Thanks for reading through and I appreciate any help.

回答1:

This page on the CocoaDev wiki contains several implementations of base64 decoding from strings. The NSData category at the bottom of the page is probably the simplest to integrate in your application.

From there, you can extract an NSData representation of your base64-encoded string. The NSData can be used to initialize a UIImage instance using the UIImage imageWithData: or initWithData: constructors.