# Storing PGraphics to List of Images?

**URL:** <https://discourse.processing.org/t/storing-pgraphics-to-list-of-images/9391>\
**Category:** Coding Questions\
**Created:** [March 17, 2019, 7:28pm UTC](https://discourse.processing.org/t/storing-pgraphics-to-list-of-images/9391 "2019-03-17T19:28:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FSXAC](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fsxac/32/3995_2.png) [@FSXAC](https://discourse.processing.org/u/FSXAC)\
**Post date:** [March 17, 2019, 7:28pm UTC](https://discourse.processing.org/t/storing-pgraphics-to-list-of-images/9391/1 "2019-03-17T19:28:13Z")

</div>

Hi all,

I want to “pre-render” some PGraphics to a list of images, what is the function to copy the PImage as an image (similar to how `image()` treats PGraphics as parameter as an image).

Here is what I want to do in code:

```auto
let pg;
let flipbook = [];

function setup() {
  // ...
  bg = createGraphics(300, 300);
  makeFlipbook();
}

function makeFlipbook() {
  for (let i = 0; i < 200; i++) {
    // ... draw stuff in 'pg'
    
    flipbook.push(pg.copy()); // ???
  }
}

function draw() {
  let frame = frameCount % flipbook.length;
  image(flipbook[frame], 0, 0);
}

```

Note that I attempted to use `.copy()` because that’s how to copy the PImage from the graphic in Processing. But that doesn’t seem to work here. Please help.

Thanks in advance.

---

<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:** [March 18, 2019, 12:32am UTC](https://discourse.processing.org/t/storing-pgraphics-to-list-of-images/9391/2 "2019-03-18T00:32:07Z")

</div>

[https://p5js.org/reference/#/p5.Image/copy](https://p5js.org/reference/#/p5.Image/copy)

should it be more like

```auto
new.copy(pg)

```

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [March 18, 2019, 12:38am UTC](https://discourse.processing.org/t/storing-pgraphics-to-list-of-images/9391/3 "2019-03-18T00:38:18Z")

</div>

I did not test it this, but your call should be like this:

```auto
 flipbook.push(pg.get());

```

The intended behavior of [get()](https://p5js.org/reference/#/p5.Image/get) should be the same in both P5.js and Processing Java.

Kf
