Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ericbreiter

macrumors member
Original poster
Jun 13, 2012
49
10
Hello,

I'm working on a little routine in Xcode and I want to read the color off a specific pixel on the screen (e.g. 100,100). I need this to work regardless whether this particular pixel is occupied by my program or something in the background. So if I for instance have something yellow in my application, on the desktop or another application in the background at 100,100 I want to read the yellow color, for instance as RGB.

I have tried various solutions, but I've come up empty. Any ideas and examples would be greatly appreciated!
 
You should mention what you have tried. That would allow others to either avoid suggesting the same paths, or possibly correcting an assumption you have.

I did the obvious net search and came up with a hint at StackOverFlow.com;
Get the color a pixel on the screen in objective-c cocoa app. It looks like half the answer as it didn't describe how you find that pixel location. My Apple doc search was more confusing in that it would take more reading time that I don't have right now.
 
It looks like half the answer as it didn't describe how you find that pixel location.

To get the device from the global location, CGGetDisplaysWithPoint may be the function to use.

Assuming CGDisplayCreateImageForRect needs the rectangle parameter in local display space (documentation just says "display space" without specifying local or global), the function CGDisplayBounds may help to convert the coordinates.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.