0

I am paring a XML and getting an image in Byte form and I have put that in a string. Now I have to draw that image.

I have tried to use various methods but no success. How can I do this?

4
  • Which methods did you try? [UIImage imageWithData:<#(NSData *)#>]is a method you tried? Commented Mar 21, 2011 at 9:39
  • @ j_freyre --YES i tried but i failed to convert my NSString to NSData Commented Mar 21, 2011 at 9:41
  • have you tried storing the Bytes as an NSData, and then using [UIImage alloc] initFromData:]? Commented Mar 21, 2011 at 9:41
  • You can convert NSString to NSData with [myDataAsString dataUsingEncoding:NSUTF8StringEncoding] Commented Mar 21, 2011 at 9:42

2 Answers 2

3

Try converting the string to NSData:

NSString* str= ....
NSData* data=[str dataUsingEncoding:NSUTF8StringEncoding]; 

Then take a look at:

UIImage *image = [[UIImage alloc] initWithData:data]; 

Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

I used this but that did not show any image to me so itried to use following code...converting UIImage to NSString and then back to image ................But again this is not working .. UIImage topImage=[UIImage imageNamed:@"iPhoneFullRes.png"]; NSData topImageData = UIImageJPEGRepresentation(topImage, 1.0); NSString str = [[NSString alloc] initWithData:topImageData encoding:NSUTF8StringEncoding]; NSData data=[str dataUsingEncoding:NSUTF8StringEncoding]; imageView.image=[UIImage imageWithData:data];
2

You can convert the byte into NSData and then you can get the image using

UIImage *image = [[UIImage alloc] initWithData:data];

OR

UIImage *image = [UIImage imageWithData:data];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.