Get pixels and colours from NSImage

后端 未结 6 1429
南方客
南方客 2021-02-06 03:10

I have created an NSImage object, and ideally would like to determine how many of each pixels colour it contains. Is this possible?

6条回答
  •  甜味超标
    2021-02-06 04:01

    Using colorAtX with NSBitmapImageRep does not always lead to the exact correct color.

    I managed to get the correct color with this simple code:

    [yourImage lockFocus]; // yourImage is just your NSImage variable
    NSColor *pixelColor = NSReadPixel(NSMakePoint(1, 1)); // Or another point
    [yourImage unlockFocus];
    

提交回复
热议问题