Shantanu
Shantanu

Reputation: 3136

Retrieve image back from NSData

I am working on an app where i have to parse and show data in the app.

I am getting the image data in form of NSData which i am encoding and converting into UIImage so that it can be displayed on UIImageView, but something is going wrong and the image is not being displayed.

Following is the code I have done,

NSData *requestdata = [[[self.resultArray objectAtIndex:indexPath.row] objectForKey:@"profile_image"] dataUsingEncoding:NSUTF8StringEncoding];
// NSLog(@"Data is::%@",requestdata);
UIImage* image = [[UIImage alloc] initWithData:requestdata];
[cell.profilePic setImage:image];

Upvotes: 0

Views: 164

Answers (1)

Mert
Mert

Reputation: 6065

With that code you do not encode - decode anything. If you mean the images are encoded with base64(most common for images in json). Then you need to decode them before you init the image.

Be sure they are encoded and if they are you can try to decode with NSData categories from the following page

http://www.cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html

Upvotes: 1

Related Questions