具有以下代码:
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组件上可见,有时则不会。只有当我“减慢”程序的执行速度时,我才能看到它,例如,当我处于调试模式时。但是当它运行得很快时,它不会显示出来。我想要它强制显示,冲洗或任何你命名的,这是可能的吗?
让我澄清一下,我想要实现的是实现一个基于帧的动画,但还不能播放它的双缓冲,能够停止它,只显示特定的单帧暂停,等等事情…
谢谢。
发布于 2011-10-27 19:27:37
结果表明,这是使用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();
}
});
……通过将此方法仅用于双缓冲,可以保证跨平台的运行时行为是相等的,并且不可预测的缓冲区行为也消失了。
https://stackoverflow.com/questions/7903071
复制相似问题