# SaveFrame function exporting black frames

**URL:** <https://discourse.processing.org/t/saveframe-function-exporting-black-frames/20582>\
**Category:** Coding Questions\
**Created:** [May 7, 2020, 12:06pm UTC](https://discourse.processing.org/t/saveframe-function-exporting-black-frames/20582 "2020-05-07T12:06:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hcanndesign](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@hcanndesign](https://discourse.processing.org/u/hcanndesign)\
**Post date:** [May 7, 2020, 12:06pm UTC](https://discourse.processing.org/t/saveframe-function-exporting-black-frames/20582/1 "2020-05-07T12:06:06Z")

</div>

Hi all,  
This is my first attempt at processing and I’m trying to export the frames of a sketch I’ve created. Unfortunately all the frames come out as a black png with no other content. This is the code I’m using in my sketch. Any advice much appreciated! \</\>

```auto
PGraphics pg;
PFont font;

void setup() {
  font = createFont("GTFAdieuTRIAL-Light.otf", 600);
  size(800, 800, P2D);
  pg = createGraphics(800, 800, P2D);

}
void draw() {
  
  background(0);
  
  pg.beginDraw();
  pg.background(216,71,26);
  pg.fill(255);
  pg.textFont(font);
  pg.textSize(160);
  pg.pushMatrix();
  pg.translate(width/2, height/2);
  pg.textAlign(CENTER, CENTER);
  pg.text("MOVING", 0, 0);
  pg.text("MOVING", 0, -375);
  pg.text("MOVING", 0, -250);
  pg.text("MOVING", 0, -125);
  pg.text("MOVING", 0, 125);
  pg.text("MOVING", 0, 250);
  pg.text("MOVING", 0, 375);
  pg.popMatrix();
  saveFrame("moving_####.png");
  pg.endDraw();
  
  
  int tilesX = 100;
  int tilesY = 100;

  int tileW = int(width/tilesX);
  int tileH = int(height/tilesY);

  for (int y = 0; y < tilesY; y++) {
    for (int x = 0; x < tilesX; x++) {
      
      int wave = int(sin(frameCount * 0.005 * (x*y) * 0.005)*60);

  // SOURCE
      int sx = x * tileW + wave;
      int sy = y * tileH;
      int sw = tileW;
      int sh = tileH;

      // DESTINATION
      int dx = x * tileW;
      int dy = y * tileH;
      int dw = tileW;
      int dh = tileH;
      
    
      copy(pg, sx, sy, sw, sh, dx, dy, dw, dh);

    }
  }
  
}

```

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [May 7, 2020, 3:08pm UTC](https://discourse.processing.org/t/saveframe-function-exporting-black-frames/20582/2 "2020-05-07T15:08:15Z")

</div>

Please format your code! Select it all and use the toolbar icon.

Are you trying to save the output of `pg` or the screen? If `pg`, try (I think) `pg.saveFrame(...)`

If the screen, move `saveFrame()` to the end of `draw()`
