Quantcast
Channel: iOS SDK Development Forums — iPhone Dev SDK
Viewing all articles
Browse latest Browse all 45

Converting from Binary to NSData and to Image

$
0
0
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;
}

Viewing all articles
Browse latest Browse all 45

Trending Articles