[SOLVED] Saving as PDF or PNG off-screen drawing

I apologize for the general nature of this question but I am somewhat lost. In Processing there is PDF Export capability that lets you save directly to PDF a drawn frame of arbitrary size. As far as I can tell no such exporting feature exists.

Here is what I have tried, I am on a MacBookAir running Lion 10.7.3 & Xcode 4.3.2:

ofBeginSaveScreenAsPDF() does as I imagine its name intends and saves only the screen.

So in main.cpp I have:

  
    ofAppGlutWindow window;  
	ofSetupOpenGL(&window, 1000, 5000, OF_WINDOW);			// <-------- setup the GL context  
   	// this kicks off the running of my app  
	// can be OF_WINDOW or OF_FULLSCREEN  
	// pass in width and height too:  
	ofRunApp( new testApp());  
      

In testApp.cpp: I have code that basically draws two columns of text (TTF) and draws connections between them, I make sure to use either ofGetWindowHeight() or ofGetHeight() to position the y-coordinates.

I have tried using ofxTileSaver and setting it up to save as one large png image:

  
save.init(1,0,true)  

which it does successfully but doesn’t save any drawn items that are drawn ostensibly outside of the size of the window on my screen.

Additionally I have used the ofImage function grabScreen, which also doesn’t grab any objects drawn outside the window on the screen.

Is this because oF isn’t drawing outside the screen?
If it is not, do I have to draw to a different context (i.e. windowless or FBO). <-Apologies if this makes no sense.

If it does how could I get at it so I can print it out?

Thanks for any assistance,
Ahmad

Hello,

So actually with a little nudge in the right direction from Zach, I was able to get an FBO to draw pixels that would be offscreen and write to a png that was very large (20 x 67 inches) and get it printed. It was a lot more straightforward than I would have imagined. Basic structure of the solution:

testApp.h

  
  
ofImage background; //initially I got some weird artifacts without creating a background image large enough for your print it drew part of my screen desktop to the FBO...  
ofFbo fbo;  
ofPixels pix;  

main.cpp

  
  
ofSetupOpenGL(&window, 1200, 4758, OF_WINDOW);	 //there is a max width and height which is apparently related to the fierceness of your graphics card, there was no problem at these dimensions with my MacBook Air  
  

testApp.cpp

  
setup()  
    fbo.allocate(ofGetWidth(), ofGetHeight()); //you definitely need to allocate your fbo prior to using it   
    pix.allocate(ofGetWidth(),ofGetHeight(),OF_IMAGE_COLOR_ALPHA); //this may not be necessary, but if you have Alpha (transparencies) you want to show you will need to make sure your pixels object allocates for it  
    background.loadImage("textProcessingBackground.png");   
  

The magic of fbo was neat especially in draw():

  
  
fbo.begin();  
//draw pretty much whatever  
fbo.end();  
fbo.draw(0,0);  
  

Yeah, I will defer to the experts, but in my particular code I have Bezier Curves and True Type Fonts, mouseOver and keyPress functionality all of which was recorded or captured in the FBO, and even stuff that gets updated in update was recorded without issue.

To save the image you will first need to write the fbo to the pixels you allocated, generally you probably don’t want to be doing that in draw but just have do it in keyPress:

  
  
void testApp::keyPressed(int key){  
if(key =='s') {  
        fbo.readToPixels(pix);  
        ofSaveImage(pix, "testimage.png", OF_IMAGE_QUALITY_BEST);  
    }  
  

You have some options as far as image quality goes, but even with my large dimensions the png was under 6MBs.

While the png image itself looked exactly as it should, the only thing I noticed is that if you choose to draw to the screen after the fbo begin.end loop; all the white values on my screen were green and the background image text did not quite look right, this maybe some idiosyncrasy with my code, but at least in my case there was nothing wrong with the image itself. So have hope!

Hopefully this helps someone else, good luck with all your projects…

6 Likes