If I use static sketches I can create a PImage right away and use it in a PGraphics buffer, then use it as a BufferedImage successfully with getNative().
How do I get a snapshot of this PGraphics buffer in time if I have a moving/animated object and a sketch with frames? This snapshot (a future frame) can be a “pause” of the animation in time or if a condition is met. e.g.:
“if frame count=X then pause”
“if a condition is met then pause”
then get the PImage
With static sketches I get the one and only frame at the end. But how could I get a specified frame in time (after x seconds or minutes) or if a condition is met? Does this have to do something with the delay() method?. How do I pause the animation or “movement” and then get a PGaraphics/PImage at this very moment?
the PImage save() serve a similar purpose, but I do not need an image file, I just need to pass the PGaraphics/PImage buffer “paused” object to getNative().
excellent example, straight to the point reply. I will try to use those “buffer save” timings in a multi instance sketch environment that expose multiple buffers. hopefully with some tweaks it will work… I will mark as a solution. Thanks a lot !
This solution is great when using processing export / save inside sketch. But if I try to get the image form an external java class with getNative() and pass it as a bufferedimage, I always get the 1st frame rendered only. If sketch is noloop that is fine, but if animated, I wish I had the option to get the image at a specific frame in time.
Is there an effective way to use the getNative() method and get a result after x time, or x frames?
Do I have to override getNative() in order to pass a “time/frame” parameter like this one?
Both of the methods return only 1st frame:
static final BufferedImage grabBufferedImage (PImage pi) {
//return new BufferedImage, Casting with getNative);
BufferedImage bi = (BufferedImage) pi.getNative();
return bi;
}
public static BufferedImage pi2bi(PImage pi) {
BufferedImage bi = new BufferedImage(pi.width, pi.height, BufferedImage.TYPE_INT_ARGB);
pi.loadPixels();
bi.setRGB(0, 0, pi.width, pi.height, pi.pixels, 0, pi.width);
return bi;
}