I have a image loader which loads the image and save it into the PC as follows:
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. How could i save the animated image from the bundle to the user PC ?
As the code show, you have only one ImageData
. For an animated GIF, you need several ImageData
. ImageDescriptor
doesn't allow that; it is too high level, you need to use SWT directly:
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.
If you still want to use SWT for that, you must save each image one by one:
int i=0;
for (ImageData data : loader.data) {
final ImageLoader saver = new ImageLoader();
saver.save("image-" + (i++) + ".gif", SWT.IMAGE_GIF);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.