# saveFrame function using background image and p3d

**URL:** <https://discourse.processing.org/t/saveframe-function-using-background-image-and-p3d/28889>\
**Category:** Coding Questions\
**Created:** [March 26, 2021, 8:59pm UTC](https://discourse.processing.org/t/saveframe-function-using-background-image-and-p3d/28889 "2021-03-26T20:59:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiernan](https://avatars.discourse-cdn.com/v4/letter/k/a3d4f5/32.png) [@kiernan](https://discourse.processing.org/u/kiernan)\
**Post date:** [March 26, 2021, 8:59pm UTC](https://discourse.processing.org/t/saveframe-function-using-background-image-and-p3d/28889/1 "2021-03-26T20:59:13Z")

</div>

I am having trouble using saveFrame to record a sketch which uses p3d with a background image. When I use saveFrame without the background image everything is captured fine and shows the sketch but when I put the background image in it only records the background image. I am very new to coding and using processing so sorry if this is too simplistic. Any help would be great.

````auto
PImage bg;
int y;
int cols, rows; 
int scl = 20; 
int w = 2500;
  int h = 3000;
  
  float flying = 0;
  
  float[][] terrain; 

void setup() {
  size (800, 533, P3D);
  cols = w/scl; 
  rows = h/scl;
  terrain = new float[cols][rows];
  bg = loadImage("Glacier_Processing.jpg");
  
}

void draw() {
  
  background(bg);
  
  flying -= 0.07;
  
  
  float yoff = flying;
  for (int y = 0; y < rows; y++) {
    float xoff = 0;
    for (int x = 0; x < cols; x++) {
      terrain[x][y] = map(noise(xoff,yoff), 0, 1, -250, 100); 
      xoff += 0.2;
    }
    yoff += 0.2; 
    
    saveFrame("output3/glacier_####.jpeg");
}
  
  
  
  strokeWeight(.45);
  stroke(0, 100, 250, 75);
      noFill();
      
      translate(width/2, height/2);
      rotateX (PI/3.65);
  translate(-w/2, -h/2); 
  for (int y = 0; y < rows-1; y++) {
    beginShape(TRIANGLE_STRIP);
    for (int x = 0; x < cols; x++) {
      vertex(x*scl, y*scl, terrain[x][y]);
      vertex(x*scl, (y+1)*scl, terrain[x][y+1]);
      //rect(x*scl, y*scl, scl, scl); 
    }
    endShape();
  }

}```
````

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 26, 2021, 9:34pm UTC](https://discourse.processing.org/t/saveframe-function-using-background-image-and-p3d/28889/2 "2021-03-26T21:34:35Z")

</div>

> [@kiernan](#):
>
> `saveFrame("output3/glacier_####.jpeg");`

Did you try to place this line at the end of draw() please

---

<div class="post-metadata">

**Author:** ![kiernan](https://avatars.discourse-cdn.com/v4/letter/k/a3d4f5/32.png) [@kiernan](https://discourse.processing.org/u/kiernan)\
**Post date:** [March 26, 2021, 9:38pm UTC](https://discourse.processing.org/t/saveframe-function-using-background-image-and-p3d/28889/3 "2021-03-26T21:38:40Z")

</div>

Yeah unfortunately it does the same thing.

When running it displays everything its supposed to, its just the saved jpegs that appear as only the background image without the sketch itself.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [March 27, 2021, 12:46am UTC](https://discourse.processing.org/t/saveframe-function-using-background-image-and-p3d/28889/4 "2021-03-27T00:46:56Z")

</div>

Hello,

It works with this line at the end of draw():

`saveFrame("output3/glacier_####.jpeg");`

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/86bffd3f67e12d106f6be880927608e23792880f.jpeg)

Reference:  
_[saveFrame() \ Language (API) \ Processing 3+](https://processing.org/reference/saveFrame_.html)_

`:)`

---

<div class="post-metadata">

**Author:** ![kiernan](https://avatars.discourse-cdn.com/v4/letter/k/a3d4f5/32.png) [@kiernan](https://discourse.processing.org/u/kiernan)\
**Post date:** [March 27, 2021, 2:43am UTC](https://discourse.processing.org/t/saveframe-function-using-background-image-and-p3d/28889/5 "2021-03-27T02:43:02Z")

</div>

Ok weird, it seems to still not be working for me. I am going to try sending it to a different computer and see if it just my computer. I haven’t updated my os in a long time so that could be it. Any chance you could send the lines of code where you placed `saveFrame("output3/glacier_####.jpeg");`

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [March 27, 2021, 2:45am UTC](https://discourse.processing.org/t/saveframe-function-using-background-image-and-p3d/28889/6 "2021-03-27T02:45:04Z")

</div>

> [@kiernan](#):
>
> could be it. Any chance you could send the lines of code where you placed `saveFrame("output3/glacier_####.jpeg");`

End of draw() loop.

See the reference for saveFrame().

`:)`
