I create a Graphics for an Image in the constructor of my MainComponent, which extends AnimatedAppComponent:
mImage.reset(new Image(Image::RGB, 200, 200, true)); mImageGraphics.reset(new Graphics(*mImage)); mImageGraphics->fillAll (Colours::blue);
I can draw into the image using mImageGraphics:
mImageGraphics->drawLine(x0, y0, x1, y1);
Then I draw the image into my MainComponent using:
g.drawImageAt(*mImage, x, y);
Everything works fine up to this point. But when I continue drawing into my image none of the new drawing shows up at the end. If I create a new Graphics(image) and draw into that then it works. But I would prefer not to have to reallocate it every time.
It is as if drawing the image into another Graphics makes the first Graphic(image) stop working. Are the Image and the original Graphics getting disconnected somehow?
My goal is to keep an image that accumulates drawing operations over time. When the paint method is called I want to just draw the current image into the window to see the changes. (Currently all of this is happening in one GUI thread but I might do the drawing into the Image in another thread eventually.)
I tried to upload my class code but was not allowed.