2012-02-13 23 views
0

CLabel内でアニメーションGIFアニメーションを取得できません。私もラベルを試しました。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

次のスニペットは、LabelCLabelの両方で、RAPと連携して動作します。

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()メソッドで何か問題が起きているはずです。 ImageImageDataから作成すると、アニメーションgifの1つのフレームのみが含まれます。

+0

ありがとう、それは私の問題を解決しました。 SWTResourceManagerでは、説明したようにImageがImageDataから作成されました。 –

関連する問題