How to Get Pixel Data in Xojo iOS?

Does anyone know how to obtain the RGB value of a pixel of an iosImage or canvas? How about manipulating it?

Thanks in advance!

I posted a project here that works for 32bit. I need to modernize it one of these days so that it works for 64bit as well. Unfortunately I plate is pretty full right now so that might take a bit.

Isn’t it true that for iOS you have no control over 32bit vs 64bit, that it depends on the device? (assuming all are running the same version of the OS)… the iPhone4s is a 32bit processor, but the iPhone5s is 64bit , and this affects the size of NSInteger

the iPhone 5c and below are 32bit devices, 5s and above are 64bit,
iPad is 32bit, iPad Air is 64bit

Yes, but you can control the code that is run with #if #endif. That project was written before 64bit was released so it only has 32bit code.

Thank you for sharing, Jason. Your approach works for me. I’ve tested it on a 4096x4096 px png without any issue, whether it’s in iOS simulator for iPhone 4, 5 or 6. Didn’t see any problem regarding 32 vs 64-bit issue the above comments mentioned. Did I miss something?

The simulator is 32bit only right now so it will definitely work there. Unfortunately it won’t work on 64bit once you deploy to a device.

I got a chance to revisit this issue and managed to make it work both on 32bit (simulator) and 64bit (tested on iPhone 6 without any issue). Only minor changes - added “img.Scale” and reversed RGB order:

dim numberOfComponents as Integer = 4 //PNG is RGBA

dim startPoint as Integer

startPoint = ((img.Width * y * img.Scale) + x * img.Scale) * numberOfComponents

dim r, g, b, a as UInt8
r = dataMB.UInt8Value(startPoint)
g = dataMB.UInt8Value(startPoint+1)
b = dataMB.UInt8Value(startPoint+2)
a = 255-dataMB.UInt8Value(startPoint+3)

The rest of the code posted by Jason remains unchanged. Thanks, Jason.