I got this Base64 gif image:
R0lGODlhDAAMALMBAP8AAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAACH5BAUKAAEALAAAAAAMAAwAQAQZMMhJK7iY4p3nlZ8XgmNlnibXdVqolmhcRQA7
Now I want to display this Base64 String within my IPhone App.
I could get this working by using the WebView:
aUIWebView.scalesPageToFit = NO; aUIWebView.opaque = NO; aUIWebView.backgroundColor = [UIColor clearColor]; [aUIWebView loadHTMLString: @"<html><body style=""background-color: transparent""><img src=""data:image/png;base64,R0lGODlhDAAMALMBAP8AAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAUKAAEALAAAAAAMAAwAQAQZMMhJK7iY4p3nlZ8XgmNlnibXdVqolmhcRQA7"" /></body></html>" baseURL:nil];
Is it possible to do the same thing by using the UIImageView?
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .
Instead, they are stored in their raw binary form in a binary (blob) column, or file. Base64 is only used as a transport mechanism, not for storage. For example, you can embed a base64 encoded image into an XML document or an email message. Base64 is also stream friendly.
You don't have to encode it. Simply make a NSUrl, it knows the "data:"-url.
NSURL *url = [NSURL URLWithString:base64String]; NSData *imageData = [NSData dataWithContentsOfURL:url]; UIImage *ret = [UIImage imageWithData:imageData];
As mentioned in the comments, you have to make sure that you prepend your data with data:image/png;base64,
or else your base64 data is useless.
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