# How to convert a PGraphic into a PImage?

**URL:** https://discourse.processing.org/t/how-to-convert-a-pgraphic-into-a-pimage/38655
**Category:** Libraries
**Created:** [September 6, 2022, 9:59am UTC](https://discourse.processing.org/t/how-to-convert-a-pgraphic-into-a-pimage/38655 "2022-09-06T09:59:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![michele\_rinaldi](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@michele\_rinaldi](https://discourse.processing.org/u/michele_rinaldi)
#### Post date: [September 6, 2022, 9:59am UTC](https://discourse.processing.org/t/how-to-convert-a-pgraphic-into-a-pimage/38655/1 "2022-09-06T09:59:58Z")

</div>

Hello,

I need to convert a PGraphics into a Pimage in the same script.  
I tried using the following command, where pg is the elaborate graphics, but it didn’t work:

`PImage img = pg.get ();`

Any suggestions?  
Thanks in advance

---

<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: [September 6, 2022, 11:17am UTC](https://discourse.processing.org/t/how-to-convert-a-pgraphic-into-a-pimage/38655/2 "2022-09-06T11:17:09Z")

</div>

pg: `get()` and `copy()` both work for me.

maybe the issue is somewhere else?

```auto

PGraphics pg;

void setup() {
  size(1100, 333);
  pg = createGraphics(40, 40);

  //
  pg.beginDraw();
  pg.background(100);
  pg.stroke(255);
  pg.line(20, 20, 37, 134);
  pg.endDraw();
  //image(pg, 9, 30); 
  //image(pg, 51, 30);
}

void draw() {

  PImage img = pg.copy ();
  //PImage img = pg.get ();

  image(img, 51, 30);
}

```

---

<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: [September 7, 2022, 9:37am UTC](https://discourse.processing.org/t/how-to-convert-a-pgraphic-into-a-pimage/38655/4 "2022-09-07T09:37:07Z")

</div>

A PGraphics is already a PImage.
