Is it possible to convert graphics object to image object?
I now design app like a audio player with waveform viewer.
On the current code, waveform is repainted every paint function called
but it is high cpu load.
So, I want to convert Grapchis object to Image object.
If it is possible,
I draw waveform using many lines(strokePath) at the initial time only and
after that I convert the waveform(Graphics Object) to image object.
I want to draw the image object
without redrawing many waveform lines when paint function called.
You can drag directly to an Image like this, and than uses that image anyway you like.
Image image(Image::ARGB, 400, 300, true);
It’s kind of the other way round…
You can either call
setBufferedToImage() for the component in question and it will draw to an image in this way for you. Or you can draw to your own image by creating a
Graphics from an image whenever you actually need to update the image (usually when the audio data changes or when the component is resized):
image = image (Image::ARGB, imageWidth, imageHeight, true); // image is member of your component
Graphics g (image);
// draw with g as usual…
Then in your `paint()` method:
`g.drawImageAt (image, 0, 0);`
Thank you very much for quick replies .
I became able to implement your advices.
CPU load is getting low very much.
Another method is to create or or more
Path objects when you need to update, instead of an image. Then draw or fill the path in the
You may find this performance even better depending on the screen density (e.g., retina on iOS/OSX) and the renderer being used.