We help IT Professionals succeed at work.

How to Create UIImage from NSData and Avatar Data of XMPP?

privateson used Ask the Experts™

Hi, This question is related to Iphone SDK, NSData and UIImage.

I am trying to create an image from the Avatar Data returned from the xmpp like the following: Away due to idle.0awaya3f549fa9705e7ead2905de0b6a804227ecdd404a3f549fa9705e7ead2905de0b6a804227ecdd404

So in this case, I assume that a3f549fa9705e7ead2905de0b6a804227ecdd404 is the photo data. So How can I transfer this into NSData?

I think if I can get the NSData object, I can easily create the UIImage, right?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

It's not that easy. Or, maybe, I do not understand the problem and your program.
NSData is a class allowing to store raw data. It is useful if your app is downloading a file. Or if you need to save a data on disk.

This way works fine:

NSString *file = @"/Library/Test/test.png";
NSImage* image = [[NSImage alloc] initWithContentOfFile:file];
NSData* data = [image TIFFRepresentation];

[image release];

Opposite is a bit problem. At least you need to know the format of the data.

You can check this nice article:
Convert an NSImage to CIImage

Few comments under the article are interesting too.