From Graphics object to Image object


#1

I have a complex path that draw around 1000 times with at least three colours. It's CPU heavy. So, I think that if I can render this Path and convert it to a Image and then draw it multiple times, it should be much friendlier on the CPU.

The problem is, I cannot find the way to convert this Path/Graphics to an Image. And I cannot simply have a PNG in my HD, since this image is dynamic (you can zoom it, with different amounts of zooms in X/Y).

In summary, I want to change the zoom and other variables -> generate the Paths/Colours -> generate the Image model -> paint it multiple times.

 

Is there is a way to do this with Juce? How could I create the Image object from a Graphics object?


#2

You create a new Image and a Graphics object that draws on that image and draw the Path on this Graphics object instead of the Graphics reference from the paint() method.

 


#3

Adding to what chrisboy2000 said, create an Image object, instantiate a Graphics context using it, Graphics g(myImage), and then draw into that context the same as you would in the paint() method.


#4

Great! I didn't see that Graphics constructor. Thank you :)