# Using PGraphics convenience methods for drawing on PImage

**URL:** <https://discourse.processing.org/t/using-pgraphics-convenience-methods-for-drawing-on-pimage/13076>\
**Category:** Coding Questions\
**Created:** [July 30, 2019, 10:29pm UTC](https://discourse.processing.org/t/using-pgraphics-convenience-methods-for-drawing-on-pimage/13076 "2019-07-30T22:29:59Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 30, 2019, 11:41pm UTC](https://discourse.processing.org/t/using-pgraphics-convenience-methods-for-drawing-on-pimage/13076/2 "2019-07-30T23:41:53Z")

</div>

> [@LoliProcessor](#):
>
> / to get a PGraphics from a PImage.

## Java Mode:

```auto
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:

```auto
def clonePImageAsPGraphics(img):
    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

```

---

_[View the full topic](https://discourse.processing.org/t/using-pgraphics-convenience-methods-for-drawing-on-pimage/13076)._
