I am using Java/Processing.org to create a drawing application.
I need to be able to reset the PGraphics object quite a lot. This is fine if I am only drawing rects,lines ect to the PGraphics object. But I need to be able to draw images to it.
Is there any way to reset the PGraphics object without calling:
graphic=createGraphics(700, 700, JAVA2D);
or is there some other way around this issue?
Here is some sample code to highlight the issue. It should crash after about 40+ clicks...
PImage img;
PImage main_image;
PGraphics graphic;
void setup(){
size(700,700);
img=loadImage("img.png");
graphic=createGraphics(700, 700, JAVA2D);
}
void draw(){
graphic.beginDraw();
graphic.image(img,mouseX,mouseY,10,10);
graphic.endDraw();
image(graphic,0,0);
}
void mouseClicked(){
graphic=createGraphics(700, 700, JAVA2D);
}