Advertise here

Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Converting from Binary to NSData and to Image

jyothijyothi connecticutPosts: 1New Users Noob
I am trying to convert binary to nsdata, and i am bale to get data but uiimage is still nil. Below is my code. Please can anyone help me on this.

NSData *data = [self dataFromBase64EncodedString:[dictionary objectForKey:@object]];
UIImage *image = [UIImage imageWithData:data];

-(NSData *)dataFromBase64EncodedString:(NSString *)string{
if (string.length > 0) {

//the iPhone has base 64 decoding built in but not obviously. The trick is to
//create a data url that's base 64 encoded and ask an NSData to load it.
NSString *data64URLString = [NSString stringWithFormat:@data:;base64,%@", string];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:data64URLString]];
return data;
return nil;
Sign In or Register to comment.