views:

94

answers:

1

I'm pretty new to Java and SWT, hoping to have one image dissolve into the next. I have one image now in a Label (relevant code):

Device dev = shell.getDisplay();
try {
    Image photo = new Image(dev, "photo.jpg");
} catch(Exception e) { }

Label label = new Label(shell, SWT.IMAGE_JPEG); 
label.setImage(photo);

Now I'd like photo to fade into a different image at a speed that I specify. Is this possible as set up here, or do I need to delve more into the org.eclipse.swt.graphics api?

Also, this will be a slide show that may contain hundreds of photos, only ever moving forward (never back to a previous image)---considering this, is there something I explicitly need to do in order to remove the old images from memory?

Thanks!!

+1  A: 

I am not aware of any swt widgets that directly support this type of functionality, your best bet would be to extend org.eclipse.swt.widgets.Canvas and adding a org.eclipse.swt.events.PaintListener that can handle drawing 2 overlapping images with a different alpha. So something like this:

addPaintListener(new PaintListener() {
    public void paintControl(PaintEvent e) {
        e.gc.setAlpha(50);
        e.gc.drawImage(image1, 0, 0);
        e.gc.setAlpha(100);
        e.gc.drawImage(image2, 0, 0);
    }
});

After that you would just have to create a thread change redraw your Canvas and change the images/alpha values at some interval.


As for your question about removing an Image from memory that is done by calling dispose() on the Image object, letting it get garbage collected won't be enough when using swt.

Yanamon