Saving The Screen As An Image

I want to enable the a person using my application to select an area on the screen. When selected, a window will open with details about what was selected. When finished, the screen area used to show details would be refreshed to the original.
I am thinking that if there was a way to save the entire screen as an image, a simple load image would do the job. Is this possible?

Typically, a sketch, particularly an animated one, would store its geometry or images in data structures from which it can render and re-render the scene. If you want to draw a pop-up over part of your scene, you would remove it by simply redrawing the scene again without the pop-up.

If you have a complex pixel-based scene that the user has generated such as from a drawing program, you would save that in an image. In Processing, you would most likely use a PGraphics which lets you issue drawing commands (line(), rect(), etc.) to it which you can display using image(). You can then draw your pop-up on top of that image.

For instance, click and drag to draw on your image. Press a key to see a pop-up where the mouse is.

PGraphics img;

void setup() {
  size( 800, 800 );
  img = createGraphics( 800, 800 );
  img.beginDraw();
  img.background( 64 );
  img.fill( 128, 64, 192 );
  img.rect( 100, 100, 300, 500 );
  img.fill( 64, 192, 96 );
  img.circle( 400, 400, 300 );
  img.endDraw();
}

void draw() {
  image( img, 0, 0 );
  if( keyPressed ) {
    push();
    translate( mouseX, mouseY );
    fill(255);
    rect( 0, 0, 200, 100 );
    fill(0);
    textSize( 20 );
    text( "This is a pop-up", 30, 50 );
    pop();
  }
}

void mouseDragged() {
  img.beginDraw();
  img.stroke( 255 );
  img.strokeWeight(3);
  img.line( pmouseX, pmouseY, mouseX, mouseY );
  img.endDraw();
}
1 Like

You have given me a great deal to think about. Image processing is new to me (I really am a beginner) and I see the advantages immediately. My project is profiling a railroad in 100 foot segments. Its scalable using a X axis scale expressed in pixels per foot and a Y scale expressed as the altitude within a range. I see now that I have an opportunity to learn.
Thank you very much,I greatly appreciate your help.