How to copy the display into a PImage?

edited September 2017 in How To...

I see that the PApplet class has some methods with the exact same names as those of PImage (copy(), filter(), set(), get()), but it seems that they are not inherited from each other and as such, I cannot call the PImage copy() method with the PApplet (this) as an argument.

Is the best way really to manually call get() and set() for each individual pixel? This seems like missing functionality, since we have an image() function that draws a PImage into the applet.

Answers

  • edited September 2017 Answer ✓

    In order to access sketch's main canvas, call getGraphics(). B-)
    Or simply use variable g or clone the PGraphics canvas via get(). :>

  • Thanks. But in my program, I draw a lot of points for my scatter plot, and it seems that using PGraphics.set() is much slower than the same code using PImage.set(). I'm guessing PGraphics somehow buffers up the draw operations and then replays them on demand (when image() is called)? I guess I'll stick to using the PImage class for now.

Sign In or Register to comment.