Grabbing from the screen (OSX)


#1

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…

http://visiblevisible.org/deliver/OF/sc-…-xample.zip

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!
zach


#2

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

Just curious. :slight_smile:

–k


#3

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


#4

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


#5

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;   
	}  


#6

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: https://github.com/genekogan/ofxScreenGrab


#7

Cool. This addon https://github.com/bakercp/ofxofxAddonsThumbnailGenerator
a similar setup to create animated gifs for ofxAddons.


#8

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


#9

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.