Reads the color of the pixel at the specified location.


func NSReadPixel(_ passedPoint: NSPoint) -> NSColor?



The pixel location to read, specified in the current coordinate system.

Return Value

The color of the pixel at the specified location.


Because the passedPoint parameter is relative to the current coordinate system, if you wish to read a pixel from a specific view, you must convert points in the view’s coordinate system to the current coordinate system before calling this function. Alternatively, you can lock focus on the view and then specify the pixel coordinate in the view’s coordinate system.

When mapping the specified point to pixel boundaries, this method rounds to the nearest pixel. For more information on how coordinate points map to the underlying pixels, see Coordinate Systems and Transforms in Cocoa Drawing Guide.