How could I extract information about pixels (such as number of pixels on width and height and RGB value for each pixel) from an NSImage in Swift?
Asked
Active
Viewed 923 times
0
-
Check code in objective C, swift is similar http://stackoverflow.com/questions/448125/how-to-get-pixel-data-from-a-uiimage-cocoa-touch-or-cgimage-core-graphics – LViet Jul 04 '16 at 09:07
1 Answers
2
You can send -size
to the image itself.
However, to get detailed data you should not ask the image itself, but one of its representations, that are instances of a subclass of NSImageRep
. The attributes you can get depends on the type of the representation. Likely you will have a NSBitmapImageRep
.
To test a pixel, you can use -colortAtX:y:
.

Amin Negm-Awad
- 16,582
- 3
- 35
- 50