We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I know usually you draw in pimage and then save to pgraphics, but is it possible to go the other way around? for example you draw the canvas image(canvas,0,0) with some effects; and then -> save that to a PImage to further effects. If that's not possible, how do you do it the other way around?
Answers
The
PGraphics
class extends thePImage
class, so an instance ofPGraphics
is an instance ofPImage
. Why do you think you need to do this?In any case, the
PImage
class contains aset()
function, which allows you to draw an image (which can be aPGraphics
instance) on top of aPImage
.Instead of directly editing the canvas pixels, I need to let the canvas pixels do their thing and then show the modified image. If I modify the actual canvas pixels those changes will be visible between frames.
Cool, and what have you tried so far? What exactly are you stuck on?
I'm not sure, I've tried just about everything for the last few hours. Basically I have two PGraphics objects which I used to control the amount of blur between two layers. However I want to get the resulting image from everything and apply a pixel transformation on it. After trying to get this working for the so many hours I don't know what's going on. I'm so confused.
You an always use
get()
at any point to grab a current PImage of any PGraphics object - including the main canvas.Oh my gosh... that works amazingly. Thank you SO much. That's a really powerful tool. One more question, is there a faster way to do exactly that? When I insert PImage output = get(); in my draw function it cuts my framerate in half.
Without seeing you full code? No idea.
Regardless if it's a PImage, or 1 of its subclasses like PGraphics, Movie, Capture, etc., if we wanna copy the pixels[] of 1 into another, as long as both of their width & height are the same, we can use arrayCopy() to do it fastest:
https://Processing.org/reference/arrayCopy_.html
Awesome, thanks. You guys are great.