0

I am recieving array of bytes from JSON webservice and it is a jpg image. i want to convert this byte array into image. on server side these bytes are correct and can be converted into image. But in Xcod i am unable to convert it into image. I have tried following Links but unable to convert bytes into image

How to get UIImage from Byte...at IPhone code

Encode Byte array to JPEG image in Objective-C

Byte Array to UIImage Objective-C

6
  • 2
    You're unable to? Why not? Does XCode refuse to boot up, or the image is too small to satisfy you? Give us some details and tell us where you got stuck. Commented Jul 26, 2011 at 6:44
  • if i use this code NSData *data = [tempDict valueForKey:@"Image"]; [image writeToFile:documentDirectoryPath atomically:YES]; It is saving image in document directory. but when i try to open it, get the following message "The file temp.jpg could not be opened" Commented Jul 26, 2011 at 6:50
  • How is your image encoded in the JSON? Base64? Commented Jul 26, 2011 at 6:51
  • @Cyrille: No it is not converted in base64. it is an array Commented Jul 26, 2011 at 6:57
  • similar question stackoverflow.com/questions/6660482/… Commented Jul 26, 2011 at 7:18

2 Answers 2

1

You can get the bytes in NSData and use the NSData to get the image in an UIImage object. Use initWithData method. Hope this helps

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

Comments

0

You can do like this

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

assuming pictureData is of type NSData.

In order to convert your byte array to NSData you pass the pointer to the char array accordingly:

NSData *pictureData = [NSData dataWithBytes:pointer];

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.