Canvas supports SWT.DOUBLE_BUFFERED, try adding that as a style in the Canvas creation:
gifCanvas = new Canvas (gifComposite, SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED);
Question
I have a thread which animates a gif image inside a Canvas control by calling it's redraw method. But there is flickering of images which is observed. I tried using the SWT.NO_REDRAW_RESIZE style bit but it didn't help.
Below is the Thread's run code
while (!UIManager.stop){
long currentTime = System.currentTimeMillis();
int delayTime = UIManager.loader.data[UIManager.imageNumber].delayTime;
while(currentTime + delayTime * 10 > System.currentTimeMillis()){
// Wait till the delay time has passed
}
UIManager.imageNumber = UIManager.imageNumber == UIManager.loader.data.length-1 ? 0 : UIManager.imageNumber+1;
display.asyncExec(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
if(!UIManager.stop){
UIManager.image = new Image(display, UIManager.loader.data[UIManager.imageNumber] );
if(!UIManager.gifCanvas.isDisposed())
UIManager.gifCanvas.redraw();
}
}
});
and the Canvas paint listener is as follows
gifCanvas = new Canvas(gifComposite,SWT.NO_REDRAW_RESIZE);
gifCanvas.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
gifCanvas.setLayoutData(introGifData);
gifCanvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.drawImage(image,0,0);
}
});
I don't know where I am going wrong. Your help will be appreciated.
Solution
Canvas supports SWT.DOUBLE_BUFFERED, try adding that as a style in the Canvas creation:
gifCanvas = new Canvas (gifComposite, SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED);