Transform UIImage into Array Byte

0

I need to transform an image into an array of bytes, how do I make this image into an Array Bytes?

    
asked by anonymous 23.10.2014 / 15:29

1 answer

1

You can use the functions UIImageJPEGRepresentation or UIImagePNGRepresentation to cover your image in NSData . From there you can allocate an array of bytes of the data size, and copy the bytes to it, as in the example below.

UIImage *image = [UImage imageNamed:@"foto.png"];
NSData *data = UIImagePNGRepresentation(image);
NSUInteger len = [data length];
Byte *bytes = (Byte*)malloc(len);
memcpy(bytes, [data bytes], len); 
    
23.10.2014 / 15:45