Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

muzammil

macrumors newbie
Original poster
Hi All !

I am trying to create an UIImage from a byte array which i get from a webservice.It comes embedded in a XML.I can parse the XML and get the byte array as a string.Then I convert the byte array (which is in NSString) to NSData. This is the code for that:-

Code:
NSString *Image_String = currentElementValue;

NSData *My_Data = [Image_String dataUsingEncoding:NSUTF8StringEncoding]

UIImage *Image_From_XML = [[UIImage alloc] initWithData: My_Data];

///////////////////////// It's not working 🙁

I got my "Image_String" as "/9j/DAPEIROEOPJVCIUMKJDFKDJFEEREMERELREMFDO......."
And in "My_Data" 12324 bytes.. and nothing in "Image_From_XML" ( 0X0 image ) 🙁
Can anyone have idea about this ???
How can i load my image which is Parse by xml (in binary format).

Thnax in Advance.
 
What format is the data? Is it PNG, JPG, etc., or the raw RGBA/etc bytes? If you don't know, I suggest you find out 😉
 
@Above: Thanx for the reply

Actually i am new in Objective C. So can you please show me some code that how can i find this ?
I think it is in jpg format. Please reply ASAP.
 
Actually i am new in Objective C. So can you please show me some code that how can i find this ?
I think it is in jpg format. Please reply ASAP.

Hi, have you solved the problem? Cause I have the same question and my image is PNG. How can I convert to byte array?
 
In order for binary data like an image to be embedded in xml it has to be encoded somehow. I guess something like base64 is used (I really don't know.) In order to make it back into an image the code needs to decode the base64, or whatever it is. That is the step that's missing from the OP's code.
 
In order for binary data like an image to be embedded in xml it has to be encoded somehow. I guess something like base64 is used (I really don't know.) In order to make it back into an image the code needs to decode the base64, or whatever it is. That is the step that's missing from the OP's code.

Thanks very much ~~
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.