# saveFrame location options processing

**URL:** https://discourse.processing.org/t/saveframe-location-options-processing/8136
**Category:** Beginners
**Tags:** homework
**Created:** [February 5, 2019, 2:17pm UTC](https://discourse.processing.org/t/saveframe-location-options-processing/8136 "2019-02-05T14:17:03Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![juriaan](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@juriaan](https://discourse.processing.org/u/juriaan)
#### Post date: [February 5, 2019, 2:17pm UTC](https://discourse.processing.org/t/saveframe-location-options-processing/8136/1 "2019-02-05T14:17:03Z")

</div>

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");`

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [February 5, 2019, 2:26pm UTC](https://discourse.processing.org/t/saveframe-location-options-processing/8136/2 "2019-02-05T14:26:45Z")

</div>

[Processing.org/reference/PImage\_get\_.html](http://Processing.org/reference/PImage_get_.html)  
[Processing.org/reference/PImage\_save\_.html](http://Processing.org/reference/PImage_save_.html)

---

<div class="post-metadata">

### Author: ![juriaan](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@juriaan](https://discourse.processing.org/u/juriaan)
#### Post date: [February 5, 2019, 2:40pm UTC](https://discourse.processing.org/t/saveframe-location-options-processing/8136/3 "2019-02-05T14:40:36Z")

</div>

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

```auto
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?

 ![icon_%23%23%23%23](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/2ed525b751719fce278708be95dc32d958f2ef1b.png)

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [February 5, 2019, 2:56pm UTC](https://discourse.processing.org/t/saveframe-location-options-processing/8136/4 "2019-02-05T14:56:21Z")

</div>

> [@juriaan](#):
>
> I want it to only save the right part of the frame.

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

> **[get() / Reference](https://processing.org/reference/get_.html)**
>
> Reads the color of any pixel or grabs a section of an image. If no parameters are specified, the entire image is returned. Use the x and y parameters to get the value of one pixel. Get a…

---

<div class="post-metadata">

### Author: ![juriaan](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@juriaan](https://discourse.processing.org/u/juriaan)
#### Post date: [February 5, 2019, 3:29pm UTC](https://discourse.processing.org/t/saveframe-location-options-processing/8136/5 "2019-02-05T15:29:43Z")

</div>

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

```auto
int q=0;
PFont font;
PImage img;

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

```

---

<div class="post-metadata">

### Author: ![clankill3r](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/clankill3r/32/1098_2.png) [@clankill3r](https://discourse.processing.org/u/clankill3r)
#### Post date: [February 5, 2019, 3:55pm UTC](https://discourse.processing.org/t/saveframe-location-options-processing/8136/6 "2019-02-05T15:55:20Z")

</div>

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

`get` is returning a PImage.

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

```

---

<div class="post-metadata">

### Author: ![juriaan](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@juriaan](https://discourse.processing.org/u/juriaan)
#### Post date: [February 5, 2019, 4:01pm UTC](https://discourse.processing.org/t/saveframe-location-options-processing/8136/7 "2019-02-05T16:01:06Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [February 5, 2019, 4:07pm UTC](https://discourse.processing.org/t/saveframe-location-options-processing/8136/8 "2019-02-05T16:07:42Z")

</div>

> [@juriaan](#):
>
> `if (q < 5) get(800, 800, 600, 600);`

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

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

`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: 🖱

> **[mousePressed / Reference](https://processing.org/reference/mousePressed.html)**
>
> The mousePressed variable stores whether a mouse button has been pressed. The mouseButton variable (see the related reference entry) can be used to determine which button has been presse…

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

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [February 5, 2019, 4:09pm UTC](https://discourse.processing.org/t/saveframe-location-options-processing/8136/9 "2019-02-05T16:09:31Z")

</div>

> [@juriaan](#):
>
> What do curly braces help?

Actually, NOTHING for 1-liner conditional statements! 😄

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [February 5, 2019, 4:13pm UTC](https://discourse.processing.org/t/saveframe-location-options-processing/8136/10 "2019-02-05T16:13:36Z")

</div>

> [@juriaan](#):
>
> But it saves it under the same name, …

You can insert _frameCount_ in the middle of the filename: 📂

> **[frameCount / Reference](https://processing.org/reference/frameCount.html)**
>
> The system variable frameCount contains the number o frames displayed since the program started. Inside setup() the value is 0 and during the first iteration of draw it is 1, etc.

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

---

<div class="post-metadata">

### Author: ![juriaan](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@juriaan](https://discourse.processing.org/u/juriaan)
#### Post date: [February 5, 2019, 4:47pm UTC](https://discourse.processing.org/t/saveframe-location-options-processing/8136/11 "2019-02-05T16:47:03Z")

</div>

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?

```auto

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!

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [February 6, 2019, 3:36am UTC](https://discourse.processing.org/t/saveframe-location-options-processing/8136/12 "2019-02-06T03:36:09Z")

</div>

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

> array

get the idea

> [@I really need help! to make a quiz](https://discourse.processing.org/t/i-really-need-help-to-make-a-quiz/7431/3):
>
> i understand it might be too much, but just take a look to see that there are some other possible program structures ways like array… to do that: ( example) String[] questions ={ "start text", "qa\n[a] bla\n[b] blb\n[c] blc", "qb\n[a]\n[b]\n[c]", "qc\n[a]\n[b]\n[c]", "end"}; String[] goodanswers={ "n.a.", "a", "c", "b", "n.a."}; int q=0, grade=0, gambler = 0; void setup() { size (500, 500); println("mouse click: LEFT: next question, RIGHT: start again"); …

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.
