How to improve Graphics strokePath profermance?

I use the code below to draw waveform according to AD data.

path.startNewSubPath (startPointX, startPointY);
for(int i=0;i<2000;i++)
   path.lineTo(pointX, pointY);
g.strokePath (path, PathStrokeType (2.0f),AffineTransform::identity);

when I draw 2000 lines one time every 100 ms, the cpu Occupancy is about 50%, it’s very high.
So I think is there another way to draw waveform fast.

Ouch! Yeah, that’s really not the best way to do it!

If you’re drawing a waveform, that’s what AudioThumbnail is for.

My waveform is special, the Audio Thumbnail is not suitable.
I just want to find a way draw fast using Graphics object.
Thank you.

1 Like

The “real” way would be to create a juce::Image, grab the juce::Image::BitmapData, and directly manipulate the pixels. This is by far the fastest and easiest method to produce high quality results.

Thanks any way.
Now I use OpenGL to draw waveform.It’s very good.

Well, the trick for extra speed would be to not use any Paths. If you can draw it just using calls to drawVerticalLine(), that’s how the AudioThumbnail class does it.

Now I just extends class OpenGLRenderer, in function renderOpenGL write some code like below:

glVertexPointer(2, GL_DOUBLE, 0, _vertices);
glDrawArrays(GL_LINE_STRIP, 0, _dataCount);

With this method, draw 2000 lines every 100 ms,the cpu is just less 2%.