Java Applet 缓冲图像
好的,这是我的代码: http://www.so.pastebin.com/Qca4ERmy
我我正在尝试使用缓冲区,以便小程序不会在 redraw() 时闪烁,但似乎我遇到了麻烦。小程序仍然闪烁......
帮忙吗?
谢谢。
我制作了一个有关此问题的快速视频:http://www.vimeo.com/12035196
OK so here's my code: http://www.so.pastebin.com/Qca4ERmy
I am trying to use buffers so the applet won't flicker upon redraw() but it seems I am having trouble. The applet still flickers....
Help?
Thank you.
I made a quick video about this problem: http://www.vimeo.com/12035196
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建一个 Swing 小程序。 Swing 默认情况下是双缓冲的,因此您不应该遇到此问题。从 Swing 教程中关于如何制作 Applet 了解创建 Swing 小程序的正确方法。
Create a Swing applet. Swing is double buffered by default so you should not have this problem. Start with the section from the Swing tutorial on How to Make Applets for the proper way to create a Swing applet.
我这样做的最好方法是创建另一个与您的小程序大小相同的图像,绘制到该图像,然后在您的绘制/更新方法中将该图像的内容复制到您的图形对象。您必须确保在绘制小程序时没有更新其他图像,否则会导致闪烁。绘图可能也应该在另一个线程中完成,只是为了让事情更容易理解。
我无权访问我的代码,因此以下内容可能有点不对劲(并且代码可能不是最有效的):
希望这有帮助!
-担
The best way I've done it is to create another image the same size as your applet, draw to that, then in your paint / update method copy the contents of that image to your graphics object. You have to make sure that you aren't updating the other image when you draw to your applet otherwise it will cause flicker. Drawing should probably be done in another Thread as well, just to make things a little easier to understand.
I don't have access to my code so the following might be a little off (and the code may not be the most efficient):
Hope this helps!
-Dan
您可以尝试使用 BufferedImage 来解决这个问题,这样您只需创建一个与您的框架兼容的 BufferedImage ,然后在将整个图像传输到上面之前绘制所有内容。
JFrame
的内容。更好的方法是通过
BufferStrategy
类使用自动缓冲,您可以阅读有关它的教程 这里。You can try to solve this issue using a
BufferedImage
, in this way you just create aBufferedImage
that is compatible with your frame and then draw everything there before blitting the whole image onto theJFrame
's content.A better approach is to use automatic buffering with
BufferStrategy
class, you can read a tutorial about it here.