2012-02-13 72 views
0

我無法在CLabel中獲得動畫GIF動畫。我也試過Label。無法獲得GIF動畫

final CLabel lblSpinner = new CLabel(this, SWT.NONE); 
lblSpinner.setImage(SWTResourceManager.getImage(Installation_4.class, "/resources/spinner_anim_16.gif")); 

怎麼了?只顯示第一個GIF。在RCP中,我必須以編程方式進行動畫製作,但在RAP中,這必須是我認爲的瀏覽器的工作。

回答

1

下面的代碼片段可與RAP,既LabelCLabel

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()方法中做錯。請注意,如果您從ImageData構建Image,這些將只包含動畫gif的單個幀。

+0

謝謝,這解決了我的問題。在SWTResourceManager中,圖像是從ImageData創建的,如您所述。 – 2012-02-16 11:35:38