Java scroll text on canvas
-
12-01-2021 - |
質問
I'm making an application where I need to scroll some text on a java.awt.Canvas
- at the moment I'm doing this by constantly calling the repaint()
method, and overriding the paint()
method in Canvas
to adjust the position each time the method is called and then draw the string at the given position.
This works, but it really eats through CPU something silly for something so simple. Is there a better, hardware accelerated way to do the task? I've tried using VolatileImage
but for some reason that made the performance noticeably worse.
I need to use Canvas
not JPanel
- I'm using VLCJ in the same project, and it needs a heavyweight component on which to play the video.
解決
You may be able to use Double Buffering and Page Flipping in this context.
Addendum: You might look at pre-rendering the full text into a depth-compatible BuffreredImage
; drawImage()
does better of it doesn't have to scale or change depths.