Save screen to large tif file (9000px x 9000px)

I have 100 moving circles all over the screen leaving a trail by puting a rectangle every frame in draw:

" void draw(){
fill(0, 10);
rect(0,0,width,height);
etc… "

I want to export the screen at a given moment to a large .tif file (9000px x 9000 px.)

Two issues here:
1/ running the programe in size(9000,9000) freezes the screen from the start and so no save can be performed.
2/ tried exporting with PGraphics, but no success…

Like to understand why certain approaches don’t work.
+
Any solutions ?

Thanks a lot !

1 Like

PGraphics is definitely the way to do it. If you had no success, then that’s what you need to figure out.

Working with a PGraphics can be frustrating because you have to make sure that every single graphics call you make is applied to your target PGraphics and not to the default. That means if you can, for instance, PGraphics pg;, then you have to use pg.background(), pg.colorMode(...), pg.stroke(...), pg.width, and so on. It only takes missing one or two of those pg. prefixes to screw up your image. And then check the PGraphics with image( pg, 0, 0, width, height); in draw() to see if before you try saving.

I have output large PGraphics up to 16x16 times a 1920x1080 image, so large sizes shouldn’t be a problem. You just have to scour your code looking for anywhere you might have made a graphics call to the default drawing surface rather than your PGraphics. The one place you MIGHT have a problem is if your particular computer doesn’t have enough video memory. I don’t know what the image size limits might be on a Raspberry Pi, for instance.

As an example, note that the circle() had to use pg.width instead of width to center correctly. Even though it was the whole point of my post, I still made that mistake when I first typed this in.

PGraphics pg;

void setup() {
  size( 900, 900 );
  pg = createGraphics( 9000, 9000 );
  
  pg.beginDraw();
  pg.background( 255, 0, 0 );
  pg.circle( pg.width/2, pg.height/2, pg.width/4 );
  pg.endDraw();
  
  image( pg, 0, 0, width, height );
}

Then you can add pg.save( "myImage.png" ); to save it.

3 Likes