I'm using web service to retrieve data. But I'm unable to convert data to image. I'm receiving data from server but when I'm converting to image it is showing null.
Asked
Active
Viewed 2.0k times
2
-
this must be covered somewhere on this site – Grady Player Sep 29 '13 at 14:05
-
4Show us what you've tried. – Hot Licks Sep 29 '13 at 14:05
-
Show code what you have tried? – Jayprakash Dubey Jan 30 '14 at 06:42
4 Answers
19
Convert NSData to UIImage :
NSData *data = ... // data that you received
UIImage *image = [UIImage imageWithData:data];
Convert UIImage to NSData (png) :
UIImage *image = [UIImage imageNamed:@"imageName.png"];
NSData *imageData = UIImagePNGRepresentation(image);
Convert UIImage to NSData (jpg) :
UIImage *image = [UIImage imageNamed:@"imageName.jpg"];
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);

Jordan Montel
- 8,227
- 2
- 35
- 40
-
i'm using saop service to retrieve data.during xml parsing they are stored in string to get the image i'm converting it to nsdata and from nsdata i want uiiimage here im getting the problem – Balakishore Sep 29 '13 at 13:39
-
1
Check out UIImage *image = [UIImage imageWithData:...];
. I'm curious what are you using now?

mmackh
- 3,550
- 3
- 35
- 51
1
In one of your comments, you suggest that the images "are stored in string". If this is the case, then image may have been base64-encoded (a common mechanism for representing binary data in a string). You should clarify this with the provider of this SOAP service.
If it has been converted to a base64 string, then you'll have to convert that back to the raw binary format before you can use imageWithData
or the like. There are a variety of base64 alternatives listed in response to How do I do base64 encoding on iphone-sdk?