2013-07-26 63 views

回答

2

您可以使用CGDisplayCreateImageForRect获得CGImageRef涵盖你感兴趣的点。一旦你有一个CGImage,您可以通过将图像呈现到自定义缓存获取的颜色值出来,或者通过使用NSBitmapImageRep'sinitWithCGImage然后colorAtX:y:。为NSBitmapImageRep法“写在堆栈溢出代码窗口中”代码会看起来像:

NSColor *MyColorAtScreenCoordinate(CGDirectDisplayID displayID, NSInteger x, NSInteger y) { 
    CGImageRef image = CGDisplayCreateImageForRect(displayID, CGRectMake(x, y, 1, 1)); 
    NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCGImage:image]; 
    CGImageRelease(image); 
    NSColor *color = [bitmap colorAtX:0 y:0]; 
    [bitmap release]; 
} 

这可能会在设备颜色空间返回的颜色。取而代之,在校准的RGB颜色空间中返回颜色可能很有用。

相关问题