开发者

On Mac's Cocoa, how do you get the RGB value of any point on the screen?

I tried

  CGPoint pt;
  pt.x开发者_如何学运维 = x;
  pt.y = y;

  NSColor* color = NSReadPixel(pt);
  float colourValue = [color greenComponent] + [color redComponent]+ [color blueComponent];
  printf("%f\n", colourValue);

but it always print out 0.0000

(if you know a method to "set" the value of a pixel on the screen too, thanks)


This CocoaDev page has several approaches for getting a pixel's color. According to the example code there you would need a transparent graphics context in the right location to be current before NSReadPixel would work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜