PGraphic not updated in JAVA2D (while in P2D it works as expected)
in
Programming Questions
•
3 years ago
Hey everyone,
I ran into something weird. When using one pgraphic in another I noticed that in JAVA2D it wasn't working as expected, while in P2D it was working fine. Here is a small code example which reproduces this issue. Try saving the image multiple times. With JAVA2D the first image is saved every time, instead of the updated image. Not a big thing, but still I was wondering why this could be happening?
I ran into something weird. When using one pgraphic in another I noticed that in JAVA2D it wasn't working as expected, while in P2D it was working fine. Here is a small code example which reproduces this issue. Try saving the image multiple times. With JAVA2D the first image is saved every time, instead of the updated image. Not a big thing, but still I was wondering why this could be happening?
- PGraphics pg;
- PGraphics pgSave;
- void setup() {
- size(500,500);
- pg = createGraphics(500,500,JAVA2D);
- pgSave = createGraphics(500,500,JAVA2D); // saves correctly only once, then stops updating the image
- // pgSave = createGraphics(500,500,P2D); // continues to update the image and thus saves correctly
- pg.beginDraw();
- pg.background(255);
- pg.endDraw();
- }
- void draw() {
- image(pg,0,0);
- }
- void mouseMoved() {
- pg.beginDraw();
- pg.ellipse(mouseX,mouseY,25,25);
- pg.endDraw();
- }
- void keyPressed() {
- if (key == 's') {
- pgSave.beginDraw();
- pgSave.image(pg,0,0);
- pgSave.endDraw();
- pgSave.save(year() + "-" + month() + "-" + day() + " " + hour() + "." + minute() + "." + second());
- }
- }
1
