1

有以下代码:

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 组件上看到图像,有时 - 不是。只有当我“减慢”程序的执行速度时,我才会看到它,例如当我处于调试模式时。但是当它运行得很快时 - 它不会显示。我希望它强制显示,刷新或任何你的名字,这可能吗?

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

谢谢你。

4

1 回答 1

3

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

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

于 2011-10-27T19:27:37.497 回答