Basically, the DigitalColor Meter takes the coordinates of the mouse, takes a screenshot of the CGImageRef around this area and then accesses the raw pixel data to calculate the RGB value.
You can find out which API applications the application calls using the nm command. In this case:
nm /Applications/Utilities/DigitalColor\ Meter.app/Contents/MacOS/DigitalColor\ Meter
This shows some interesting challenges:
U _CGDisplayBounds U _CGGetDisplaysWithPoint U _CGSCaptureWindowsContentsToRectWithOptions U _CGSCurrentInputPointerPosition U _CGSGetOnScreenWindowCount U _CGSGetOnScreenWindowList
CGS * routines are private SPIs - 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
source share