Reputation: 497
My Client is asking for the ability to incorporate Animated GIF files as part of the app I'm building. I can't use the designer to load them because he uses a website I built to "self-edit" content for the app and it uploads it to AWS S3 where my app retrieves data from.
I need some help understanding my options.
1) Can a CodenameOne App retrieve and display an animated GIF? (I think the answer is still no unless there's recent developments)
2) If I were to process his Animated Gifs into a "spritesheet", how can I take that spritesheet and turn it into an animated image (An example would really help, I've been trying to understand Timelines and AnimationObject classes and so far my result is not working well. it seems very jittery and like its skipping frames compared to when I loaded the Gif as an animation in the designer:
AnimationObject[] gifAnimationObjects = { AnimationObject.createAnimationImage(URLImage.createToStorage(placeholder,"spriteImage.png","http://www.jamesvankessel.com/spriteImage.png"),0,0)};
gifAnimationObjects[0].defineFrames(500,375,200);
Timeline gif = Timeline.createTimeline(6000, gifAnimationObjects, new Dimension(500,375));
BoxLayout.encloseY(new Label(gif))
.... code continues and adds the layout to the form
3) Is it possible to provide a list of images and have the app load them from URL then turn them into a fairly simple animated image? I think this can be done with Slider but I'm not sure if this is performant and a recommended way to do this. Again, an example woul dbe of great help (if there's already an exmaple of this somewhere, please help me find it).
thanks in Advance!
Upvotes: 2
Views: 97
Reputation: 52770
That's the wrong direction, these classes don't really match and aren't designed for runtime decoding. The right way to do this is to just subclass image and decode the gif frames so you can draw the image. I wanted to provide a reference so I googled gif decoder and found this.
It looked simple so I wrapped it myself in a cn1lib. The source might look intimidating but it's mostly the original gif decoder code. All of my code is at the bottom and it's relatively simple.
Upvotes: 2