saveFrame location options processing

Hey couldn’t find this anywhere online but is it possible to save a image from a specific location on my canvas. my canvas is 1400 x 800. but I want the image of only the right
600 x 800.

Thanks

This is what I have:

if ( q > 5 ) save ("icon_####.png");

Processing.org/reference/PImage_get_.html
Processing.org/reference/PImage_save_.html

Hey GotoLoop,

I can’t seem to figure it out? sorry if I’m asking dumb questions here but could you elaborate a bit on this? so far from the reference I tried

pimg.save(filename)

but it doesn’t recognise it or am I able to put in coordinates.

here’s a screenshot of a save, I want it to only save the right part of the frame. how would I go about and do this?

You need to invoke get()'s overloaded version w/ 4 arguments in order to get a PImage rectangular section of the canvas:

this is what I have gotten so far. anything I’m missing? I’m new to processing

int q=0;
PFont font;
PImage img;

  if ( mouseButton == LEFT ) q++;
  if ( q > 5 ) get(800, 800, 600, 600);

If you are new I really recommend curly braces around if statements.

get is returning a PImage.

PImage section = get(800, 800, 600, 600);
section.save("dsafdsafdsf.png");

1 Like

Perfect thank you for the answer. I see it saving now. but it saves it under the same name, so I can’t do let’s say 50. any tips?

also I’m using a lot of if’s in my program, what do curly braces help?

As @clankill3r has already pointed out, you’re not storing the PImage returned by get()! :expressionless:

You can instead invoke PImage::save() method chained after PApplet::get() too: :bulb:

if (q > 5) get(800, 800, 600, 600).save("img.png");

Also, we need to check for mousePressed 1st when mouseButton is used outside a mouse callback: :computer_mouse:

if (mousePressed & mouseButton == LEFT) ++q;

Actually, NOTHING for 1-liner conditional statements! :smile:

You can insert frameCount in the middle of the filename: :open_file_folder:

if (q > 5) get(800, 800, 600, 600).save("img." + frameCount + ".png");

1 Like

everything seems to work, thanks for the help bro’s!
since this goes way out of league for teachers at my school. maybe ya’ll can judge this piece of code?


int q=0;
PFont font;
PImage img; 



void setup() {
  size (1400, 800);
  font = loadFont ("Futura.vlw");
  textFont(font); 
  rect(800, 0, 600, 800);
}

void draw() { 
  fill(255); 
  rect(0, 0, 800, 400); // question panel
  rect(0, height/2, 400, 400);//left box
  rect(400, height/2, 400, 400);//right box
  rect(800, 800, 1600, 1600); //Drawscape
  
  fill(0);
  textSize(32);


  //QUESTION 1 

  if (q==0) text("Ik zie mijzelf als sociaal", 200, 200);
  if (q==0) text("ja", 200, 600); 
  if (q==0) text("nee", 600, 600); 

  if (q==0) fill(255); 

  //QUESTION 2

  if (q==1) text("Ik wil graag op vakantie", 200, 200);
  if (q==1) text("ja", 200, 600); 
  if (q==1) text("nee", 600, 600); 


  if (q==2) text("Ik ben gelukkig zoals ik ben", 200, 200);
  if (q==2) text("ja", 200, 600); 
  if (q==2) text("nee", 600, 600); 


  //QUESTION 4

  if (q==3) text("Ik hou van avontuur", 200, 200);
  if (q==3) text("ja", 200, 600); 
  if (q==3) text("nee", 600, 600); 


  //QUESTION 5

  if (q==4) text("ik ben vaak niet mijzelf", 200, 200);
  if (q==4) text("ja", 200, 600); 
  if (q==4) text("nee", 600, 600); 


  if (q==5) text("ik wil eventjes lekker dansen", 200, 200);
  if (q==5) text("ja", 200, 600); 
  if (q==5) text("nee", 600, 600);
}

void mousePressed() {

  if ( mouseButton == LEFT ) q++;

  if (q > 5) rect (0, 0, 800, 800); 
  
  if (q == 6) get(800,0, 600, 800).save("img." + frameCount + ".png");
  
  if (q == 7) exit(); 
 
//LINES QUESTION 1 


  
    if (q == 1 && mouseX > 0 && mouseX < (0 + 400) && mouseY > 400 && mouseY < (400 + 400))
      line (1100, 400, 1100, 100);
  

  
    if (q == 1 && mouseX > 400 && mouseX < (400 + 400) && mouseY > 400 && mouseY < (400 + 400))
      line (1100, 400, 900, 0);
  

  //LINES QUESTION 2 

  
    if (q == 2 && mouseX > 0 && mouseX < (0 + 400) && mouseY > 400 && mouseY < (400 + 400))
      line (1100, 400, 1200, 200);
  
  
    if (q == 2 && mouseX > 400 && mouseX < (400 + 400) && mouseY > 400 && mouseY < (400 + 400))
      line (1100, 400, 800, -100);
  

  //lines QUESTION 3

  if (q == 3 && mouseX > 0 && mouseX < (0 + 400) && mouseY > 400 && mouseY < (400 + 400))
    line (1100, 400, 1300, 400);

  if (q == 3 && mouseX > 400 && mouseX < (400 + 400) && mouseY > 400 && mouseY < (400 + 400))
    line (1100, 400, 1100, 100); 

  //lines QUESTION 4

  if (q == 4 && mouseX > 0 && mouseX < (0 + 400) && mouseY > 400 && mouseY < (400 + 400))
    line (1100, 400, 1400, 800);

  if (q == 4 && mouseX > 400 && mouseX < (400 + 400) && mouseY > 400 && mouseY < (400 + 400))
    line (1100, 400, 1100, 100); 

  //lines QUESTION 5

  if (q == 5 && mouseX > 0 && mouseX < (0 + 400) && mouseY > 400 && mouseY < (400 + 400))
    line (1100, 400, 1500, 1600);

  if (q == 5 && mouseX > 400 && mouseX < (400 + 400) && mouseY > 400 && mouseY < (400 + 400))
    line (1100, 400, 1600, 500); 

  //lines QUESTION 6 

  if (q == 6 && mouseX > 0 && mouseX < (0 + 400) && mouseY > 400 && mouseY < (400 + 400))
    line (1100, 400, 1600, 3600);

  if (q == 6 && mouseX > 400 && mouseX < (400 + 400) && mouseY > 400 && mouseY < (400 + 400))
    line (1100, 400, 1100, 100);
}

only if you want ofcourse! thanks for the help so far!

1 Like

@juriaan
good that you got it running.
you remember i talk about the option to use

array

get the idea

here and run it to see how you can pack some things compared to your actual program structure.

and, if you use google like:
[ quiz site:processing.org ]
you would have found lots of good things to read.