简体   繁体   English

eclipse插件:将动画图像保存到PC中

[英]eclipse plugin: save animated image into PC

I have a image loader which loads the image and save it into the PC as follows: 我有一个图像加载器,它加载图像并将其保存到PC中,如下所示:

ImageLoader saver = new ImageLoader();
saver.data = new ImageData[] { ImageDescriptor.createFromURL(
            FileLocator.find(bundle, new Path("icons/img.gif"), null))
            .createImage().getImageData() };
saver.save("D:/img.gif", SWT.IMAGE_GIF);

But when i trying to save animated gif, the saved image is not animated. 但是,当我尝试保存gif动画时,保存的图像没有动画。 How could i save the animated image from the bundle to the user PC ? 如何将动画图像从捆绑包保存到用户PC?

As the code show, you have only one ImageData . 如代码所示,您只有一个ImageData For an animated GIF, you need several ImageData . 对于动画GIF,您需要几个ImageData ImageDescriptor doesn't allow that; ImageDescriptor不允许这样做; it is too high level, you need to use SWT directly: 级别太高,您需要直接使用SWT:

final ImageLoader loader = new ImageLoader();
loader.load(FileLocator.find(bundle, new Path("icons/img.gif"), null).openStream()); // closing the stream would be appreciable :)

You can then try to save directly, but I think the SWT library is unable to save animated GIF. 然后,您可以尝试直接保存,但是我认为SWT库无法保存动画GIF。
If you still want to use SWT for that, you must save each image one by one: 如果仍要使用SWT,则必须一张一张保存每个图像:

int i=0;
for (ImageData data : loader.data) {
    final ImageLoader saver = new ImageLoader();
    saver.save("image-" + (i++) + ".gif", SWT.IMAGE_GIF);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM