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

sjakobi
  • 3,546
  • 1
  • 25
  • 43
TalaT
  • 943
  • 2
  • 12
  • 20
  • 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. –  Jul 26 '11 at 06: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" – TalaT Jul 26 '11 at 06:50
  • How is your image encoded in the JSON? Base64? – Cyrille Jul 26 '11 at 06:51
  • @Cyrille: No it is not converted in base64. it is an array – TalaT Jul 26 '11 at 06:57
  • similar question http://stackoverflow.com/questions/6660482/byte-array-to-uiimage-objective-c/6660543#6660543 – Maulik Jul 26 '11 at 07:18
  • @Maulik: I have already searched on it. check the third link. it doesn't work for me – TalaT Jul 26 '11 at 08:02

2 Answers2

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

stack2012
  • 2,146
  • 2
  • 16
  • 23
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];
Man of One Way
  • 3,904
  • 1
  • 26
  • 41