TalaT
TalaT

Reputation: 953

convert bytes array into image

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

Upvotes: 0

Views: 4616

Answers (2)

Man of One Way
Man of One Way

Reputation: 3980

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];

Upvotes: 0

stack2012
stack2012

Reputation: 2186

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

Upvotes: 1

Related Questions