How to access pixels of an NSBitmapImageRep?

Posted by Paperflyer on Stack Overflow See other posts from Stack Overflow or by Paperflyer
Published on 2010-03-26T19:11:00Z Indexed on 2010/03/26 19:13 UTC
Read the original article Hit count: 366

I have an NSBitmapImageRep that is created like this:

NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] 
                              initWithBitmapDataPlanes:NULL
                                            pixelsWide:waveformSize.width
                                            pixelsHigh:waveformSize.height
                                         bitsPerSample:8
                                       samplesPerPixel:4
                                              hasAlpha:YES
                                              isPlanar:YES
                                        colorSpaceName:NSCalibratedRGBColorSpace
                                           bytesPerRow:0
                                          bitsPerPixel:0];

Now I want to access the pixel data so I get a pointer to the pixel planes using

unsigned char *bitmapData;
[imageRep getBitmapDataPlanes:&bitmapData];

According to the Documentation this returns a C array of five character pointers. But how can it do that? since the type of the argument is unsigned char **, it can only return an array of chars, but not an array of char pointers.

So, this leaves me wondering how to access the individual pixels. Do you have an idea how to do that?

(I know there is the method – setColor:atX:y:, but it seems to be pretty slow if invoked for every single pixel of a big bitmap.)

© Stack Overflow or respective owner

Related posts about core-graphics

Related posts about objective-c