Byte Array to NSData

Subhendu Kumar Mukherjee picture Subhendu Kumar Mukherjee · Aug 8, 2012 · Viewed 43.7k times · Source

In a WebService JSON response is coming. In the response, there is image is coming as a byte array. I have to show the image in a UIImageView. I am trying to convert the byte array to NSData. But not getting how to do that. Any help would be appreciated. I am confident that the byte array has image data in it. Sample Byte array for your reference:

        (137,
        80,
        78,
        71,
        ...
        66,
        96,
        130)

Thanks

Answer

Paresh Navadiya picture Paresh Navadiya · Aug 8, 2012

Here is an example of getting your data into a NSData object.

const unsigned char bytes[] = {values here};
NSData *data = [NSData dataWithBytes:bytes length:sizeof(bytes)];
NSLog(@"%@", data);