开发者

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

开发者 https://www.devze.com 2023-02-19 20:31 出处:网络
I tried CGPoint pt; pt.x开发者_如何学运维 = x; pt.y = y; NSColor* color = NSReadPixel(pt); float colourValue = [color greenComponent] + [color redComponent]+ [color blueComponent];

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

精彩评论

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