How to save two different PGraphics in one jpg file?

edited May 2016 in How To...

For example I use two or more PGraphics as a drawing layers, and the question is how to save them all to one jpg or png file?

Tagged:

Answers

  • edited May 2016

    2 image() + 1 saveFrame().

  • can you post a code example?

  • edited May 2016
    PGraphics layer1, layer 2;
    
    image(layer1);
    image(layer2);
    
    saveFrame(dataPath("2Layers.jpg"));
    
  • But for saving PGraphics I shall use layer1.saveFrame and layer2.saveFrame, isn't it? I don't want to save all the canvas, I want to save just few selected PGraphics.

  • edited May 2016

    The canvas is itself a PGraphics. >-)
    If you don't wanna use the canvas for the image(), just make another PGraphics for it and save() it.

  • so, I don't want to use the canvas, and I'm using more than one additional PGraphics for my drawing layers, and the question is - how to save more than one PGraphics in one file.

  • edited May 2016 Answer ✓

    I've already answered that: make another PGraphics to replace the canvas, then save() it. [-(

  • edited May 2016

    I am assuming that all your layer images are the same size. Lets assume that each layer is w x h pixels and you have n layers. To save these as a single file create a new PGraphics object of size w * n x h pixels. Then draw the layers as a series of horizontal tiles on the big graphic and save it.

    The reverse process would be to load the large graphic and use get(..) to retrieve the individual tiles.

  • I want save different PGraphics layers like a photoshop "flatten image" operation, so, if canvas size was 800x600, and my different PGraphics was 800x600, I want my final image to be 800x600.

  • Answer ✓

    I am assuming that all your layer images are the same size. Lets assume that each layer is w x h pixels and you have n layers. To save these as a single file create a new PGraphics object of size w x h pixels. Then draw the layers onto the graphic in turn to flatten them then save the flattened image.

  • I will try this, thanks

Sign In or Register to comment.