java图形重绘方法实际上是如何工作的 [英] how java graphics repaint method actually works

查看:363
本文介绍了java图形重绘方法实际上是如何工作的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用java 2d图形应用程序,在我的研究重绘是重绘我们的图形浪费了大量资源。
但是我想知道什么重绘是什么,是什么以及如何有效地使用它,为我画布上的许多可移动动态对象安全快速地线程?

解决方案

我首先要阅读执行自定义绘画在AWT和Swing中绘画



重绘 RepaintManager 发出请求以绘制部分或全部一个组件。 RepaintManager 将决定绘制的内容和绘制内容,可能将重绘请求合并为尽可能少的更新(因此重复调用重绘实际上可能会减慢你的绘制过程。)



RepaintManager 然后推送在事件调度线程上绘制事件。这可以确保在EDT的上下文中处理paint事件。



在Swing中进行绘制时,有许多可能的解决方案可以提高速度和资源管理。 / p>

您可以考虑实施自己的双缓冲策略,将更新绘制到屏幕外缓冲区,准备好后,切换到活动缓冲区,这将被绘制。



这意味着油漆很快,因为所有工作都已经完成(大概是在后台线程中)。



例如......





您还可以查看被动与主动渲染,但我非常肯定你知道你是什么让自己为... ...


I've just started working with java 2d graphics applications, on my studies repaint is redrawing our graphics wasting a lot of resources. but I want to know what repaint is, does and how to use it efficiently, thread safely and fast for many movable dynamic objects on my canvas?

解决方案

I would start by having a read through Performing Custom Painting and Painting in AWT and Swing

repaint makes a request to the RepaintManager to paint part or all of a component. The RepaintManager will decide what and how much will be painted, possible consolidating repaint requests into as small a number of updates as possible (so repeatedly calling repaint could actually slow your paint process).

The RepaintManager then pushes a paint event onto the Event Dispatching Thread. This ensures that the paint event is handle within the context of the EDT.

There are many possible solutions for improving speed and resource management when it comes to painting in Swing.

You could consider implementing your own double buffering strategy, painting your updates to an off screen buffer and when ready, switching to the active buffer, which will get painted.

This means that the paint is quick as all the work has already being done (presumably in a background thread).

For examples...

You could also take a look at Passive vs. Active Rendering, but I'd be very sure that you know what you're getting yourself in for...

这篇关于java图形重绘方法实际上是如何工作的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆