It might be simplest to pass NULL
for the planes
parameter. Then, after the image rep has been allocated and initialized, ask it for its -bitmapData
and copy your data into that. This approach is suggested in the docs:
If planes is NULL or an array of NULL pointers, this method allocates enough memory to hold the image described by the other arguments. You can then obtain pointers to this memory (with the getPixel:atX:y: or bitmapData method) and fill in the image data. In this case, the allocated memory will belong to the object and will be freed when it’s freed.
Emphasis added.