Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get pixels and colours from NSImage

Tags:

cocoa

nsimage

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

like image 286
Nippysaurus Avatar asked Jan 03 '10 05:01

Nippysaurus


1 Answers

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];
like image 190
iamamac Avatar answered Sep 28 '22 08:09

iamamac