gpt4 book ai didi

Java SWT GC,如何强制刷新双缓冲图像?

转载 作者:行者123 更新时间:2023-11-29 06:08:13 24 4
gpt4 key购买 nike

有如下代码:

image = new Image(display, imageData);
offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height);
/* Draw the off-screen image to the shell. */
shellGC.drawImage(offScreenImage, 0, 0);

... 执行底部指令后:shellGC.drawImage(offScreenImage, 0, 0); 有时我会在 shellGC 组件上看到图像,有时 - 不是。只有当我“减慢”程序的执行时,例如当我处于 Debug模式时,我才能看到它。但是当它运行得很快时 - 它不会显示。我希望它被强制显示、刷新或随便你怎么调用它,这可能吗?

让我澄清一下,我想要实现的是实现一个基于帧的动画,但还不能双缓冲播放它,能够停止它,只显示暂停的特定单帧等等。 .

谢谢。

最佳答案

事实证明,这是使用 SWT 双缓冲的唯一安全方法:

canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
//Obtain the next frame
ImageData imageData = imageDataArray[iad.imageNumber];
Image imageFrame = new Image(display, imageData);

// Create the image to fill the canvas
Image image = new Image(display, canvas.getBounds());

// Set up the offscreen gc
GC gcImage = new GC(image);

//Draw the image offscreen
gcImage.setBackground(event.gc.getBackground());
gcImage.drawImage(imageFrame, 0, 0);

// Draw the offscreen buffer to the screen
event.gc.drawImage(image, 0, 0);

imageFrame.dispose();
image.dispose();
gcImage.dispose();
}
});

....通过仅将此方法用于双缓冲,可以保证跨平台平等的运行时行为,并且不可预测的缓冲行为也消失了。

关于Java SWT GC,如何强制刷新双缓冲图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7903071/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com