How to Draw Off-screen and Save to a File


Hi folks,

My question is I would like to be able to have the various drawing commands, like ofEllipse for example, draw to a memory buffer and not the screen and then save that drawing as a file. For example, here is the code in Processing to accomplish that very task.

PGraphics png;   // buffer to hold the picture  
void setup() {  
 png = createGraphics(4000,4000, JAVA2D); //create buffer bigger than screen  
 png.beginDraw();  // okay  - go  
 png.background(0,0,0);  // set background to black       
 png.ellipse(100,100,2000,2000);   // draw an ellipse  
 png.ellipse(3100,3100,900,900); // draw an ellipse  
 png.endDraw(); // okay - done"MyOutputPicture.PNG"); // save the buffer to a PNG file  
} // end setup  

Can someone advise me as to what would be the equivalent in openframeworks?

Thanks, Jim

1 Like

Looking for answer to the same problem.
I’m using Mac OS X and I always have a black bar in the middle of the grabbed image.

1 Like

Make an fbo, draw to that, then load it into an image. something like

ofFbo fbo;
ofImage img;

fbo.allocate(100, 100, GL_RGBA);

ofClear(0, 255);


something like that anyway.


Hi, pants.

I met this error when run fbo.readToPixels(img.getTextureReference());

“No matching member function for call to ‘readToPixels’”.



from @bemoregt.

What’s wrong to me?


I’ve always been saving fbos to disk using the following code

 ofPixels pix;
 ofSaveImage(pix, fileName + ofToString(ofGetFrameNum()) + ".png", OF_IMAGE_QUALITY_BEST);

Where fileName is a string variable with the name of the file I’d want it to be, declared earlier. Also, this is usually in my update and saves as an image sequence, which is why ofGetFrameNum() is used so as to not overwrite the saved file on every update cycle. Can be omitted if you’re only saving once.

1 Like

if helpful this is some code I use for generating high res / large images from OF:

the code is oriented towards 8.5x11 aspect ratio but you can adjust those numbers in setup. it gives you the largest possible offscreen fbo. when you hit space it saves a png.

this is the code I use for my own printing ( and it’s pretty easy – I get about 7000x9000 pixels on my graphics card

for larger stuff you you can look at tile renderers, etc…


Thank you for this code Zach. I wanted to know (if you want to share with us) which print machine are you using for your art ?


epson p800 on hot press bright

1 Like