So, this basically what I'm curious about :
Any ideas? Pointing me to the right direction would also be welcome.
Hint : I would be more interested in a native Objective-C/Cocoa approach.
Basically, DigitalColor Meter gets the mouse coordinates, takes a CGImageRef screenshot around that area and then accesses the raw pixel data to calculate the RGB value.
You can discover which APIs an application calls by using the nm
command. In this case:
nm /Applications/Utilities/DigitalColor\ Meter.app/Contents/MacOS/DigitalColor\ Meter
Which reveals some interesting calls:
U _CGDisplayBounds
U _CGGetDisplaysWithPoint
U _CGSCaptureWindowsContentsToRectWithOptions
U _CGSCurrentInputPointerPosition
U _CGSGetOnScreenWindowCount
U _CGSGetOnScreenWindowList
The CGS* routines are private SPI - on the bright side, there is a public API equivalent called CGWindowListCreateImage()
Once you have a CGImageRef, you can access the raw pixel data using:
CGImageGetDataProvider
CGDataProviderCopyData
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With