I’m looking for the best way to quickly and repeatedly “blit” RGB bitmap data to a specific area within a Mac OS X window, for the purpose of displaying video frames coming from a custom video engine in real time. The data is in a simple C-style array containing a 32-BPP bitmap.
On Win32, I’d setup HWND and HDC’s, copy the raw data into its memory space, and then use BitBlt(). On iOS, I’ve done it via UIImageView, although I didn’t fully assess the performance of that approach (really didn’t need to in that particular limited case). I have neither available to me on Mac OS X with Cocoa, so what should I do?
I know there are several bad or convoluted ways for me to accomplish this, but I’m hoping someone with experience can point me to something that’s actually meant for this use and/or is performance efficient while being reasonably straightforward and reliable.
Thanks!
I would recommend either creating
NSImages orCGImages with your data and then drawing them to the current context.If you use
NSImage, you’ll need to create anNSBitmapImageRepwith the data of your image. You don’t need to copy the data, just pass the pointer to it as one of the parameters to the initializer.If you use
CGImage, you can create aCGBitmapContextRefusingCGBitmapContextCreate(), and as above, just pass a pointer to the existing image data. Then you can create aCGImagefrom it by callingCGBitmapContextCreateImage().