无法获取 GIF 动画

发布于 2025-01-04 19:42:50 字数 291 浏览 0 评论 0原文

我无法在 CLabel 中获取动画 GIF。我也尝试过标签。

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

怎么了?仅显示第一个 GIF。在 RCP 中,我必须以编程方式制作动画,但在 RAP 中,我认为这必须是浏览器的工作。

I can't get an animated GIF animated within a CLabel. I also tried Label.

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

What's wrong? Only the first GIF is displayed. In RCP I have to animate programatically but in RAP this must be a job for the browser I thought.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静赏你的温柔 2025-01-11 19:42:50

以下代码片段适用于 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 的单个帧。

The following snippet works with RAP, with both Label and 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
      }
    }
  }
}

If this doesn't work with your image, then the problem is in the image image itself. Otherwise, you must be doing something wrong in your SWTResourceManager.getImage() method. Please note that if you construct an Image from ImageData, these will only contain a single frame of the animated gif.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文