Reputation: 602
I am able to get the base 64 string of an image using the following code,
UIImage *thumbImage = [UIImage imageNamed:@"image.png"];
NSData *theThumbImageData = UIImageJPEGRepresentation(thumbImage,0.1);
NSString *str = [theThumbImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
Now i am trying to get the image back from base64 string and below code is used for that purpose.
NSString *string = @"base64 encoded string retrieved from server";
NSData *base64Data = [imageData dataUsingEncoding:NSUTF8StringEncoding];
UIImage* theMultimediaImage = [[UIImage alloc] initWithData:[base64Data base64EncodedDataWithOptions:0]];
The problem am facing here is that during the image conversion from base64 string am getting NIL value.
Please help me to rectify my mistake. Note: Followed the link ,Converting NSString to NSData and vice versa
Regards, Bhat
Upvotes: 0
Views: 570
Reputation: 277
In the first line of code you are initializing an NSString variable named 'string' but in the 2nd line of code you are trying to extract data from a different (presumably string) variable named 'imageData'.
Upvotes: 1