JavaSWTGC,如何强制刷新双缓冲映像?

JavaSWTGC,如何强制刷新双缓冲映像?,java,graphics,swt,doublebuffered,double-buffering,Java,Graphics,Swt,Doublebuffered,Double Buffering,具有以下代码: 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(of

具有以下代码:

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组件上看到图像,有时-不是。只有当我“减慢”程序的执行时,例如当我处于调试模式时,它才可见。但是当它跑得快的时候,它就不显示了。我想要它被有力地展示出来,脸红,或者不管你叫它什么,有可能吗

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


谢谢。

结果表明,这是使用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();
              }
            });

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

此代码是否在paint事件上运行?否,它没有在paintControl上运行。事实上,这正是错误所在。它在windows7上运行,但在其他平台上很可能出现问题。我从一个论坛上取了上面的例子,它显然是错误的。我被告知,唯一安全的方法是从PaintListener.paintControl(PaintEvent)调用绘制到小部件的GC。我现在就是这么做的。我修复了我的问题,现在不再有不可预测的缓冲行为。我正在等待所需的时间来回答我自己的问题。@PatlaDJ你应该接受你的答案。:)