Get pixels and colours from NSImage

后端 未结 6 1274
南方客
南方客 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 03:40

    Get an NSBitmapImageRep from your NSImage. Then you can get access to the pixels.

    NSImage* img = ...;
    NSBitmapImageRep* raw_img = [NSBitmapImageRep imageRepWithData:[img TIFFRepresentation]];
    NSColor* color = [raw_img colorAtX:0 y:0];
    

提交回复
热议问题