How to Get UIImage from a 'Base64String' format raw image data, on iPhone?

冷暖自知 提交于 2019-12-09 03:23:09

问题


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.



来源:https://stackoverflow.com/questions/847875/how-to-get-uiimage-from-a-base64string-format-raw-image-data-on-iphone

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