简体   繁体   English

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

[英]Java SWT GC, how to flush the doublebuffering image forcefully?

Have the following code: 有以下代码:

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);

... after executing the bottom instruction: shellGC.drawImage(offScreenImage, 0, 0); ...执行底部指令后: shellGC.drawImage(offScreenImage, 0, 0); sometimes I get the image visible on the shellGC component, sometimes - not. 有时,我在shellGC组件上看到图像,有时-不。 I get it visible only when I "slow down" the execution of the program , for example when I am in debug mode. 只有当我“减慢”程序的执行时,例如当我处于调试模式时,我才能看到它。 But when it runs fast - it does not show. 但是当它快速运行时 - 它没有显示出来。 I want it forcefully shown, flushed or whatever you name it, is it possible ? 我希望它有力地展示,冲洗或任何你的名字,它有可能吗?

Let me clarify that what I want to achieve is to implement an animation which is frame based, but yet to be able to play it double buffered, able to stop it, show only particular single frame paused, and etc things... 让我澄清一下,我想要实现的是实现一个基于帧的动画,但是还能够播放双缓冲,能够阻止它,只显示特定的单帧暂停等等......

Thank you. 谢谢。

It came out that this is the ONLY SAFE way to double buffer with SWT: 结果表明这是使用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();
              }
            });

.... by using this method ONLY for doublebuffering there is guaranteed crossplatform equal runtime behaviour, and the unpredictable buffer behaviour is also gone. ....通过仅使用此方法进行双缓冲,可以保证跨平台等同的运行时行为,并且不可预测的缓冲行为也消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM