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

man2manno

macrumors member
Original poster
Mar 21, 2009
55
0
Hey guys, is there a way to take a UIImage and store it temporalily as an NSString then decode it later to view elsewhere. I took the image and made it NSData then converted that to an NSString as shown in the code below:

Code:
NSData *imageData = UIImageJPEGRepresentation(imageView.image, 90);
	NSString *imageString = [[NSString alloc] initWithData:imageData encoding:NSASCIIStringEncoding];

And ImageString returns a value of weird characters, which I expected, but now when I go to add ImageString to another string using the stringWithFormat method it becomes a null value. Why? Or is there a better way to do this? Thanks.
 
Why do you want to store UIImage as NSString? I am sure this can be avoided.
Theoritacally you get array of bytes and if you encode it and decode it same way, it should work, i think...
 
Last edited:
Well in the long run, I have an NSString with values that are sent to a php which then places those values into my server. However, I also want it to send an Image along with the values. And the easiest way I can think of doing that would be to encode the image some way into the NSString with the other values and send only one request to my server.
 
You can't do that, at least not reliably. Arbitrary binary data can't be stored as a string, without converting it to an ascii format.

You might try converting to base64, or some other ascii format.
 
Okay, I have heard about base64, how do you convert an NSData or NSString to base64? Example would be awesome, thanks a lot.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.