Grabbing from the screen (OSX)


I needed to get something that would grab pixels below the OF app (ie, screen grab) for a student. this is my first attempt which wraps some cocoa code for that……

here’s a shot of it in action (showing the pixels directly below the OF app window in a texture):

I’ve uploaded the app - but to compile this code, you’ll need to compile for 10.5 and also, add the appkit framework.

the code is pretty simple. the .h file (with corresponding .m) exposes this function:

unsigned char * pixelsBelowWindow(int x, int y, int w, int h);  

that returns BGRA array of pixels in the rectangle x,y,w,h. I manually convert that to RGBA for opengl uploading, but you can do what ever you want with those pixels – process them, manipulate them, etc.

I’ve noticed it work pretty well in some cases (ie, live updating in realtime on top of quicktime videos, etc), and flickers sometimes with things like youtube videos (which might be blitted to the screen in a different way?). give it a try and let me know. Also, it’s not thoroughly tested so it might be radically inefficient.

take care!


Would you mind telling us what your student is planning to do with that?

Just curious. :slight_smile:



I think his plan is to process live video from skype but not sure what the final outcome will be. the idea is to open up the skype video window and have the OF app running fullscreen on top… - z


Hi !
it works, but error at the mentioned color space, there is more blue component at the captured the image.
OF 6.01

could be usefull use this function to fix the recieved color space


Solved, manually convert from ARGB -> RGBA

	for (int i = 0; i < w*h; i++){  
		unsigned char r1 = data[i*4]; // mem A  
		data[i*4]   = data[i*4+1];   
		data[i*4+1] = data[i*4+2];   
		data[i*4+2] = data[i*4+3];   
		data[i*4+3] = r1;   


tried some of the screen capturing addons but none of them worked for me, found this discussion which and it worked for me, so i’ve packaged it up into a new addon:


Cool. This addon
a similar setup to create animated gifs for ofxAddons.


I can’t make it work on Xcode 6.1. Any idea or another solution for grabbing the screen?


I tried the ofxScreenGrab addon and it worked but not with multiple desktop with Mission Control, the app just crash I think because it tried to access memory not allocated to it which points to something offscreen.