# Screen to PGraphic?

**URL:** <https://discourse.processing.org/t/screen-to-pgraphic/13622>\
**Category:** Coding Questions\
**Created:** [August 26, 2019, 3:41pm UTC](https://discourse.processing.org/t/screen-to-pgraphic/13622 "2019-08-26T15:41:29Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [August 26, 2019, 10:06pm UTC](https://discourse.processing.org/t/screen-to-pgraphic/13622/7 "2019-08-26T22:06:51Z")

</div>

The main problem in real applications is that, if you are drawing to the canvas every frame and then copying all the pixels off, then you are always wiping the destination buffer every frame, so you lose the potential flexibility of having a drawable graphics buffer in the first place.

So this is better for a snapshot – which you can do anytime with `g.copy()` or just `copy()`, giving you a PImage. If you want to make that PImage into a PGraphics for further drawing, then in addition to copying pixels you may want to also copy the pixel density properties. See this example of `clonePImageAsPGraphics`:

> [@Using PGraphics convenience methods for drawing on PImage](https://discourse.processing.org/t/using-pgraphics-convenience-methods-for-drawing-on-pimage/13076/2):
>
> Java Mode: PGraphics clonePImageAsPGraphics(final PImage img) { final PGraphics pg = createGraphics(img.width, img.height); pg.format = img.format; pg.pixelDensity = img.pixelDensity; pg.pixelWidth = img.pixelWidth; pg.pixelHeight = img.pixelHeight; pg.beginDraw(); pg.endDraw(); img.loadPixels(); pg.loadPixels(); arrayCopy(img.pixels, pg.pixels); pg.updatePixels(); return pg; } Python Mode: def clonePImageAsPGraphics(img): pg = createGraphics(img.width, img.heig…

…but then you might want to convert it just-in-time for drawing if you aren’t actually drawing to it every frame.

---

_[View the full topic](https://discourse.processing.org/t/screen-to-pgraphic/13622)._
