2013-07-26 88 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顏色空間中返回顏色可能很有用。

相關問題