Dhiraj Umale
Dhiraj Umale

Reputation: 92

Convert base64string to UIImage

I have image base64 string,so please tell me how to convert base64string to UIImage. I am using following code but its not working.

NSString *base64String=[NSString stringWithFormat:@"%@",[objDIC objectForKey:@"signDriver"]];
NSURL *url = [NSURL URLWithString:base64String];    
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *ret = [UIImage imageWithData:imageData];

Thanks in advance

Upvotes: 1

Views: 326

Answers (2)

zaph
zaph

Reputation: 112857

Get the code from the Matt Gallagher Cocoa With Love site. Go to the section: "Handling Base64 on the iPhone", "Decoding Base64".

Turn in a bug report to Apple requesting base64 support be added, I have, the more the better chance Apple will add it to the SDKs.

Upvotes: 1

Jay Wardell
Jay Wardell

Reputation: 2290

[NSData dataWithContentsOfURL:url] expects to be given a file: URL that points to a file on disk with the given image in a format that UIImage (actually, Core Graphics) knows how to open.

You already have the image data stored in base64String, so you should be able to just grab the data from the string using dataUsingEncoding.

Upvotes: 0

Related Questions