以下代码片段适用于 RAP,同时具有Label
和CLabel
:
public class AnimatedGifSnippet implements IEntryPoint {
public int createUI() {
Display display = new Display();
Shell shell = new Shell( display );
shell.setLayout( new GridLayout() );
Image image = createImage( display, "resources/loading.gif" );
Label label = new Label( shell, SWT.NONE );
label.setImage( image );
shell.layout();
shell.open();
return 0;
}
private Image createImage( Display display, String resourceName ) {
ClassLoader classLoader = getClass().getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream( resourceName );
if( inputStream == null ) {
throw new IllegalArgumentException( "Resource not found: " + resourceName );
}
try {
return new Image( display, inputStream );
} finally {
try {
inputStream.close();
} catch( IOException exception ) {
// TODO handle exception
}
}
}
}
如果这不适用于您的图像,则问题出在图像图像本身。否则,你的方法一定是做错了什么SWTResourceManager.getImage()
。请注意,如果您构建Image
from ImageData
,这些将仅包含动画 gif 的单帧。