Based on http://stackoverflow.com/questions/3284185/get-pixel-color-of-uiimage
B4X:
Sub GetPixelColor(Bitm As Bitmap, x As Int, y As Int) As Int
Dim NativeMe As NativeObject = Me
Dim UIColor As Object = NativeMe.RunMethod("GetPixelColor:::", Array (Bitm,x,y))
return NativeMe.UIColorToColor(UIColor)
End Sub
#If OBJC
- (UIColor *)GetPixelColor:(UIImage *)bitmap :(int)x :(int)y {
CFDataRef pixelData = CGDataProviderCopyData(CGImageGetDataProvider(bitmap.CGImage));
const UInt8* data = CFDataGetBytePtr(pixelData);
int pixelInfo = ((bitmap.size.width * y) + x ) * 4;
UInt8 red = data[pixelInfo];
UInt8 green = data[(pixelInfo + 1)];
UInt8 blue = data[pixelInfo + 2];
UInt8 alpha = data[pixelInfo + 3];
CFRelease(pixelData);
return [UIColor colorWithRed:red/255.0f green:green/255.0f blue:blue/255.0f alpha:alpha/255.0f];
}
#End If