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!!
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.Canvasand adding aorg.eclipse.swt.events.PaintListenerthat can handle drawing 2 overlapping images with a different alpha. So something like this: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
Imagefrom memory that is done by callingdispose()on theImageobject, letting it get garbage collected won’t be enough when using swt.