'Image get pixel RGBA

I have Swift code that shows the first pixel from RGBA of UIImage:

let cgImage = image.cgImage
let data = cgImage.dataProvider?.data
let dataPtr = CFDataGetBytePtr(data)

let components = (
    dataPtr[0],
    dataPtr[1],
    dataPtr[p2],
    dataPtr[3]
)

when I print the value of components I get:

  - .0 : 220
  - .1 : 188
  - .2 : 129
  - .3 : 255

I want to convert this code and use it on Objective-C project, so I run this code on the same image:

CGImageRef cgImage = image.CGImage;
CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(cgImage));
UInt8 * dataPtr = (UInt8 *) CFDataGetBytePtr(data);

UInt8 components[4] = {
    dataPtr[0],
    dataPtr[1],
    dataPtr[2],
    dataPtr[3]
};

And when I print it I get:

ܼ\x81\xff\U00000004

Any idea how I can get the value I get in the swift value?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source