Java Graphics:每次重绘时,我都会得到一个黑色闪光 [英] Java Graphics: Each time it repaints, i get a blackflash

查看:251
本文介绍了Java Graphics:每次重绘时,我都会得到一个黑色闪光的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Java绘图函数很新,但是我有一个样本直方图,我构建。点击按钮后,我用随机值重建直方图。但是,每次按下按钮重新绘制时,我都会在重新绘制之前获得黑色闪光。我记得听说这很常见,修复与缓冲有关。任何建议?

解决方案

当你绘制的第一件事是清除你的画布。你看到的闪光是随着事物的绘制而变成空白的画布。如果你想减慢速度,你会看到每一个东西都出现在屏幕上,一次一个。



你可以通过所谓的双缓冲来解决这个问题。

您将屏幕绘制到屏幕外图像。然后,将图像一次性绘制到屏幕上。

I'm pretty new to the java draw functions, but I have a sample histogram that I build. on button click, i have it rebuilding the histogram with random values. However, every time i hit the button to repaint, i get a black flash before it redraws. I remember hearing this was pretty common and the fix had something to do with buffering. Any advice?

解决方案

The first thing you do when you draw is clear your canvas. The flash you see is the blank canvas as things get drawn. If you were to slow it down fast enough, you would see each thing appear on the screen, one at a time.

You can get around this by what's called double buffering.

You paint your screen to an off-screen image. Then you paint your image to the screen all at once.

这篇关于Java Graphics:每次重绘时,我都会得到一个黑色闪光的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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