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?
Thanks porneL
I could find a Base64 script using google: Base64.m
So I modified it a little bit and could get a working test code:
You don't have to encode it. Simply make a NSUrl, it knows the "data:"-url.
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.Swift 4+
In my case worked a solution proposed here by @Masche. As I needed it in Swift 2.0 so:
cStringUsingEncoding:
ofNSString
useful.NSData
instance usingdataWithBytes:length:
[UIImage imageWithData:]
to load it.