views:

28

answers:

3

Hello

I developed an asp.net web service that send an image and i want to convert the received data stream to an UIImage in my iPhone

this is a sample of what i get from the web service

R0lGODlhbQCdAOYA...KsxbcSAAOw==

thank you in advance !

+2  A: 

This is an base64 encoded string, so you need to first decode it and then put it into an NSData object. The next thing is to create an UIImage from the NSData object, this can be done like this:

NSData *myData;
UIImage *image = [UIImage imageWithData:myData];
JustSid
A: 

this is what i tryed to do. I use the method dataWithBase64EncodedString: to decode and then i instanciate the UIImage with imageWithData: method but i have exc_bad_access error.

ejjerbi
The exc_bad_access comes from somewhere else. Most probably sending a message to an already released object.
Stelian Iancu
A: 

And in order to encode/decode Base64 encoded strings into NSData, see the following post. At the end there's a link to a NSData category that does Base64 encoding/decoding.

Stelian Iancu
i used this NSData category and UIImage *image = [UIImage imageWithData:myData]; and i get an exc_bad_access
ejjerbi
Do you retain the myData variable before doing what you posted above? If you look at the code in the category, the NSData that is returned is autoreleased. Anyway, can you edit your post and put the whole code for your method (or the whole relevant part).
Stelian Iancu
thank you ! that's it, i just replaced *image = [UIImage imageWithData:myData]; by *image = [[UIImage imageWithData:myData] copy]; and replaced retain the myData accessor by assigni
ejjerbi
Just out of curiosity, why did you replace retain with assign and used copy instead of retain? Copy creates a whole new object out of myData. Why isn't retain enough in this scenario?
Stelian Iancu
BTW, if this was the answer you were looking for, please accept it. Thanks!
Stelian Iancu