Animated gif image

Hi
I like to create an animated gif image from a given set of images with java. I like to do this with the given set of java api as I do not want to use a commercial graphics library. Can anyone provide me with a sample example.
Thanks

Hi
I like to resize a gif image. Currently i am using the following code but the resized image is not smooth.
public BufferedImage resizeImage(BufferedImage img, int newW, int newH)
          int w = img.getWidth();
          int h = img.getHeight();
          BufferedImage dimg = new BufferedImage(newW, newH, img.getType());
          Graphics2D g = dimg.createGraphics();
          g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
          g.drawImage(img, 0, 0, newW, newH, 0, 0, w, h, null);
          g.dispose();
          return dimg;
Is there a way to resize a gif image in a smooth way as the example given in the gif4j library
Thanks

Similar Messages

  • Animated Gif Image does not render correctly on screen

    I have added animated gif image to the scene it does not render correctely.it shakes on the screen. plz give me any suggestion
    i use following code
    Image logo= new Image(getClass().getResourceAsStream("images/image.gif"));
    logoLabel.setGraphic(new ImageView(logo));

    Hello user,
    I think gif are rendered smoothly.
    Are you sure you are not making many object of same images everytime?
    Thanks.
    Narayan

  • Animated GIF image gets distorted while playing.

    Hi,
    I have some animated gif images which I need to show in a jLabel and a jTextPane. But some of these images are getting distorted while playing in the two components, though these images are playing properly in Internet Explorer. I am using the methods insertIcon() of jTextPane and setIcon() of jLabel to add or set the gif images in the two components. Can you please suggest any suitable idea of how I can get rid of this distortion? Thanks in advance.

    In the code below is a self contained JComponent that paints a series of BufferedImages as an animation. You can pause the animation, and you specify the delay. It also has two static methods for loading all the frames from a File or a URL.
    Feel free to add functionality to it, like the ability to display text or manipulate the animation. You may wan't the class to extend JLabel instead of JComponent. Just explore around with the painting. If you have any questions, then feel free to post.
    The downside to working with an array of BufferedImages, though, is that they consume more memory then a single Toolkit gif image.
    import javax.swing.JComponent;
    import java.awt.image.BufferedImage;
    import java.awt.Graphics;
    import javax.imageio.ImageIO;
    import javax.imageio.ImageReader;
    import javax.imageio.stream.ImageInputStream;
    public class JAnimationLabel extends JComponent {
        /**The default animation delay.  100 milliseconds*/
        public static final int DEFAULT_DELAY = 100;
        private BufferedImage[] images;
        private int currentIndex;
        private int delay;
        private boolean paused;
        private boolean exited;
        private final Object lock = new Object();
        //the maximum image width and height in the image array
        private int maxWidth;
        private int maxHeight;
        public JAnimationLabel(BufferedImage[] animation) {
            if(animation == null)
                throw new NullPointerException("null animation!");
            for(BufferedImage frame : animation)
                if(frame == null)
                    throw new NullPointerException("null frame in animation!");
            images = animation;
            delay = DEFAULT_DELAY;
            paused = false;
            for(BufferedImage frame : animation) {
                maxWidth = Math.max(maxWidth,frame.getWidth());
                maxHeight = Math.max(maxHeight,frame.getHeight());
            setPreferredSize(new java.awt.Dimension(maxWidth,maxHeight));
        //This method is called when a component is connected to a native
        //resource.  It is an indication that we can now start painting.
        public void addNotify() {
            super.addNotify();
            //Make anonymous thread run animation loop.  Alternative
            //would be to make the AnimationLabel class extend Runnable,
            //but this would allow innapropriate use.
            exited = false;
            Thread runner = new Thread(new Runnable() {
                public void run() {
                    runAnimation();
            runner.setDaemon(true);
            runner.start();
        public void removeNotify() {
            exited = true;
            super.removeNotify();
        /**Returns the animation delay in milliseconds.*/
        public int getDelay() {return delay;}
        /**Sets the animation delay between two
         * consecutive frames in milliseconds.*/
        public void setDelay(int delay) {this.delay = delay;}
        /**Returns whether the animation is currently paused.*/
        public boolean isPaused() {
            return exited?true:paused;}
        /**Makes the animation paused or resumes the painting.*/
        public void setPaused(boolean paused) {
            synchronized(lock) {
                this.paused = paused;
                lock.notify();
        private void runAnimation() {
            while(!exited) {
                repaint();
                if(delay > 0) {
                    try{Thread.sleep(delay);}
                    catch(InterruptedException e) {
                        System.err.println("Animation Sleep interupted");
                synchronized(lock) {
                    while(paused) {
                        try{lock.wait();}
                        catch(InterruptedException e) {}
        public void paintComponent(Graphics g) {
            if(g == null) return;
            java.awt.Rectangle bounds = g.getClipBounds();
            //center image on label
            int x = (getWidth()-maxWidth)/2;
            int y = (getHeight()-maxHeight)/2;
            g.drawImage(images[currentIndex], x, y,this);
            if(bounds.x == 0 && bounds.y == 0 &&
               bounds.width == getWidth() && bounds.height == getHeight()) {
                 //increment frame for the next time around if the bounds on
                 //the graphics object represents a full repaint
                 currentIndex = (currentIndex+1)%images.length;
            }else {
                //if partial repaint then we do not need to
                //increment to the the next frame
    }

  • Problem at displaying animated gif images !!!!!!!!!!!!

    hello everyone......i am trying to display an animated gif image..............so till far i have no issues on this....
    but i face problem when :
    i have created a class called SimpleGame which extends JPanel....
    public class SimpleGame extends JPanel
    //code
    public void paintComponent(Graphics g)
    //code to draw image
    }now i have written another class with main method
    public class MyGame extends SimpleGame
    public MyGame()
            JFrame frame=new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800, 600);
            frame.setUndecorated(true);
            frame.setLocationRelativeTo(null);
            frame.getContentPane().add(this);
            frame.setVisible(true);
            this.repaint();
    }so image gets displayed but only one frame of animated image......image that is displayed is static.....since it is a animated gif,,,,,so some how animation is not rendered......only one frame is displayed......
    why is it happening ??
    if i try to display animated image from a single class i mean my paintComponent method and main method is at same class then i do not face problem.....
    but if my paint method is in another class and i am using that method from another class then animation does not get rendered.........
    any help !!!!! please...........

    class SimpleGame extends JPanel
    Image img=new ImageIcon("y.gif");
    public void paintComponent(Graphics g)
    g.drawImage(img,150,150,this);
    }main class//
    class MyGame extends SimpleGame
    public MyGame()
            JFrame frame=new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800, 600);
            frame.setUndecorated(true);
            frame.setLocationRelativeTo(null);
            frame.getContentPane().add(this);
            frame.setVisible(true);
            this.repaint();
    public static void main(String[] args)
    new MyGame();
    }my image gets displayed.......but only single frame of a animated image....animation is not happening..........

  • Animated GIF Image on a JPanel.

    How can I display an animated GIF image on a JPanel? It should animate after displaying.
    Regards

    I think this code should display an animated GIF image on a JPanel.
    -Mani
    import javax.swing.*;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.*;
    public class Animation {
    public static void main(String args[]) {
    JLabel imageLabel = new JLabel();
    JLabel headerLabel = new JLabel();
    JFrame frame = new JFrame("JFrame Animation");
    JPanel jPanel = new JPanel();
    //Add a window listner for close button
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    // add the header label
    headerLabel.setFont(new java.awt.Font("Comic Sans MS", Font.BOLD, 16));
    headerLabel.setText("Animated Image!");
    jPanel.add(headerLabel, java.awt.BorderLayout.NORTH);
    //frame.getContentPane().add(headerLabel, java.awt.BorderLayout.NORTH);
    // add the image label
    ImageIcon ii = new ImageIcon("d:/dog.gif");
    imageLabel.setIcon(ii);
    jPanel.add(imageLabel, BorderLayout.CENTER);
    frame.getContentPane().add(jPanel, java.awt.BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);
    }

  • Where can I find video training to make animated GIF images?

    I would like to get more info on how to make animated GIF images with my Photoshop for my WordPress blog here  http://www.getfreewordpressthemesnow.com

    Hello Bill,
    you could have a look at http://helpx.adobe.com/photoshop/using/creating-frame-animations.html >>> ... till save the animation
    and at the end: Adobe also recommends >>> http://helpx.adobe.com/photoshop/using/saving-files-graphics-formats.html#save_in_gif_form at
    If the German language is no problem for you, you could use http://praxistipps.chip.de/photoshop-animiertes-gif-erstellen_1485
    Hans-Günter

  • How combine a jpeg image & animated gif image & save  it as GIF ?

    i have an jpeg image, & also aminated gif image, how do i place the animated gif image over (in the center of the image) a jpeg image & save it as gif file ??

    First thing you need to do is stop thinking in terms of file formats once the files are in photoshop they are all the same. The exception being vector vs raster. But in this instance the process is rteally the same so 6 on one hand a half a dozen on the other. Or as some would say Tomatoe, tomahtoe(mispelled on purpose).
    The jpeg I would assume is the background image and the gif image is the fore ground object. Open the jpeg, and then place the gif file. As long as the fore ground object has transparency, your job is pretty much done. If not, then it will be up to you to mask what you want to keep vs what you don't and apply that selection to the foregrounds layer as a mask.
    Google the net or skim the users manual for the keywords - mask, selections, quickmask, pen tool, paths. Each of these can in one way or another take care of your issue.
    It would be worth your time to also go through the numerous videos about photoshop and see how its done.
    Either go to adobe tv,
    Itunes podcasts
    or one of the following web sites:
    http://kelbytv.com/
    http://creativesuitepodcast.com/

  • Question about animated GIF image

    I am working on a new site. My client (using Safari 1.x with
    OS10.3x) tells
    me that this ani GIF doesn't load properly. I see it fine in
    10.4x, with
    both Safari 2x and FF1.5x, and on the PC. Whazzup wit dat?
    http://www.murraytestsite.com/nni/n_default.shtml
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================

    Could this be a problem?
    2 different background images defined for the same container?
    #wrapper #topContent {
    background-image: url(Images/Anim.gif);
    and...
    #topContent {
    background-repeat: no-repeat;
    background-image: url(../images/Index.jpg);
    height: 208px;
    Just a thought..........
    John Malone
    ==============
    "Murray *ACE*" <[email protected]> wrote
    in message
    news:[email protected]...
    | That's it, John. Thanks.... It makes sense now that Joe
    pointed out to
    me
    | the background image-ness of that! I had just copied and
    pasted from a
    page
    | that I didn't create....
    |
    | --
    | Murray --- ICQ 71997575
    | Adobe Community Expert
    | (If you *MUST* email me, don't LAUGH when you do so!)
    | ==================
    |
    http://www.dreamweavermx-templates.com
    - Template Triage!
    |
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    |
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    |
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    | ==================
    |
    |
    | "John Malone" <[email protected]> wrote in
    message
    | news:[email protected]...
    | > Container not big enough....
    | >
    | > #wrapper #topContent {
    | > height: 167px;}
    | >
    | > Change to
    | >
    | > #wrapper #topContent {
    | > height: 208px;}
    | >
    | > That will do it I think...
    | > --
    | > John Malone
    | > ==============
    | > "Murray *ACE*" <[email protected]>
    wrote in message
    | > news:[email protected]...
    | > | John:
    | > |
    | > | Thanks. You are right - I had missed that. Why would
    that be? Any
    | > idea?
    | > |
    | > | --
    | > | Murray --- ICQ 71997575
    | > | Adobe Community Expert
    | > | (If you *MUST* email me, don't LAUGH when you do
    so!)
    | > | ==================
    | > |
    http://www.dreamweavermx-templates.com
    - Template Triage!
    | > |
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    | > |
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    | > |
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    | > | ==================
    | > |
    | > |
    | > | "John Malone" <[email protected]> wrote in
    message
    | > | news:[email protected]...
    | > | > Murray,
    | > | > The ani is cool BUT using FF & IE6 The ani
    does not show the last
    | > frame.
    | > | > Loaded and reloaded in both but still no last
    frame..
    | > | > (the one that has the saying "Where Ideas...."
    on the bottom).
    | > | > Just wanted you to know
    | > | > --
    | > | > John Malone
    | > | > ==============
    | > | > "Murray *ACE*"
    <[email protected]> wrote in message
    | > | > news:[email protected]...
    | > | > |I am working on a new site. My client (using
    Safari 1.x with
    | > OS10.3x)
    | > | > tells
    | > | > | me that this ani GIF doesn't load properly. I
    see it fine in
    10.4x,
    | > | > with
    | > | > | both Safari 2x and FF1.5x, and on the PC.
    Whazzup wit dat?
    | > | > |
    | > | > |
    http://www.murraytestsite.com/nni/n_default.shtml
    | > | > |
    | > | > |
    | > | > | --
    | > | > | Murray --- ICQ 71997575
    | > | > | Adobe Community Expert
    | > | > | (If you *MUST* email me, don't LAUGH when you
    do so!)
    | > | > | ==================
    | > | > |
    http://www.dreamweavermx-templates.com
    - Template Triage!
    | > | > |
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    | > | > |
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    | > | > |
    http://www.macromedia.com/support/search/
    - Macromedia (MM)
    | > Technotes
    | > | > | ==================
    | > | > |
    | > | > |
    | > | > |
    | > | >
    | > | >
    | > |
    | > |
    | >
    | >
    |
    |

  • Why does the iPhone convert animated .GIF images?

    I saved a bunch of animated .GIF files on my iPhone.
    When I imported them onto my computer, they were all single framed .JPG files.
    Why does the iPhone convert the images, and is there any way to prevent this?
    Thanks!

    you can play gif in webView ,just the same way you load a jpeg or png..
    NSString *path = [[NSBundle mainBundle] pathForResource:@"santa" ofType:@"gif"];
    NSURL *url = [NSURL fileURLWithPath:path isDirectory:NO];
    /* Load the request. */
    [myWebView loadRequest:[NSURLRequest requestWithURL:url]];
    the gif that is locally saved will be loaded.

  • Animated gif images not working, n73 problem pleas...

    my phone is n73music. when i try to use animated or gif images as wallpapers, the images are not moving as they should do in standby mode on the display. what could be the problem, please advice. thankyou.

    Sorry, N73/ME is a s60 phone and s60 doesnt support moving animated GIG, PNG file format as wallpaper

  • Set an animated gif image as wallpaper?

    When I looked at this picture, I wanted to make it my wallpaper.
    I call this kind of thing "ants' fights" because I don't know the word for it. (please tell me)
    '$ feh --bg-center xx.gif' does not set it as animated. Actually feh doesn't show you the animation even when you use it to view the image.
    It must be a simple question I believe. Anyone knows how?

    sergey6661313 wrote:
    na12 wrote: gifview --animate --new-window root  animated.gif
    next level :
    $ gifview --animate --new-window root animated.gif
    X Error of failed request: BadWindow (invalid Window parameter)
    Major opcode of failed request: 3 (X_GetWindowAttributes)
    Resource id in failed request: 0xffffffff
    Serial number of failed request: 7
    Current serial number in output stream: 8
    output unchanged, as before, but something is wrong ...
    I have the same error on my Arch 64bit,
    Here is new PKGBUILD with the patch.
    https://github.com/StanleyPham/gifsicle-patch
    Last edited by Stanley_00 (2013-11-16 14:05:00)

  • Adobe Software : Happy New Year 2014 Animated GIF Image

    Hello, I am looking for a Adobe Software with the help of which i can create some awesome animate GIF Image and Desktop HD Wallpapers of   Happy New Year 2014 so that i can host that on one of my blog  for all the readers of my blog as i got many comments for publishing some best Animated HD wallpapers of Happy New YEar 2014. So anyone can help me with this ?

    Photoshop Elements can produce animated gifs and any wallpaper you can dream up.

  • How to use an animated .GIF image as the texture in Cp4 ?

    Hello all
    I wish to create an animated banner and use it as the texture in Captivate 4.
    As I know texture supports only image formats( JPEG, PNG, GIF,etc). So, I have created a small animation in Photoshop and saved in GIF format and used it as the texture. But when I preview the movie it is displayed as an image but not the animation.
    Is there any solution for this problem?
    Kind regards,
    Kartik Pullela

    1. Instal this package: http://nugetmusthaves.com/Package/WpfAnimatedGif2. Use the code below:
    <Window x:Class="WpfAnimatedGif.Demo.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:gif="http://wpfanimatedgif.codeplex.com"Title="MainWindow"Height="350"Width="525"><Grid><Image gif:ImageBehavior.AnimatedSource="Images/animated.gif"/></Grid>I found this on: http://wpfanimatedgif.codeplex.com/, and this is the useful solution because <MediaElement /> doesn't show the .gif image, and that's pretty strange.

  • I finished making an animated .gif image in FireWorks. My question is, how do I convert it into video so that when I edit video, that every video editing program recognizes it? Long story short, How do I convert animated .gif files into video formats?

    I worked in Adobe FireWorks to make the animated .gif. What program do I use to convert the file from .gif to any video format: .mp4, .m4v, .avi, .wmv, etc. I want to convert it into video format, so that QuickTime Player plays the video, I can insert it into iMovie '11 and edit, and also insert it into Final Cut Pro X and edit video.

    Thanks for getting back with me so promptly.  It has taken me this time to connect with the proper people to find out the information you requested.
    The camera used to film the class was a Panasonic AG-HMC40P, owned by a local cable TV station; they use Kodak video encoding software, and a SD card was used to store the video.   The file extension is .mts, and the mime file is MPEG 2 transport.  He said I probably need an AVCHD converter, and the Mac app store lists 8 of those options, 4 free and 4 for up to $9.99.  He said I'll also need a converter for later plans of posting on YouTube or on the website, and while some of those in the app store might work for the later needs, he knows one app called "Compressor" that would work for the uploading later.  He also suggested I could try renaming the .mts file to .MP2T, but he wasn't sure that would work.
    They don't work with Macs at the studio, but I had thought I could have some lessons there in editing, and apply what I learned to my iMac and iMovie.
    First, though, I have to be able to see it and review it!
    Thanks again!

  • Loss transparency in an animated GIF image when resizing

    Hi Friends,
    I have to write a program to resize GIF, JPEG , and PNG images. I wrote and it works but when i resize a GIF file it loses its transparency and give a black color for transparent area.
    I used a GifDecoder found at www.fmsware.com/stuff/GifDecoder.java
    and a gif encoder found at jmge.net/java/gifenc/Gif89a090b.zip.
    i don't know where the problem is .
    i have some small problems in here.
    How can i preserve the transparency of GIF image?
    How can i set a transparent color in Graphic2D object? smtimes it may help me. or error may be in the encoder.
    Help me guys.
    Thanks and regards,
    Manjula

    Java comes with gif encoder/decoders.
    Gifs are indexed images. This means that, for example, each pixel is an 8 bit value that is used to look up the correct 24 bit value in the index table. Gifs handle transparency by allowing one particular pixel value to be nominated as transparent.
    If you just rescale the image then you will likely cause pixels with the magic "transparent" value to change their value and become normal pixels. Alternately pixels that are not transparent may have their values changed such that they are transparent.
    Possibly the easyist solution to to force the image into a full RGBA image. Scale this then perform post processing on the image. I.e convert it back into an indexed image, looking at the values of the alpha channel (prior to making it indexed and if they are high enough then modify the corresponding pixel in the indexed image to have the magic transparent value. Then use Metadata passed to your Image writer to indicate which value is transparent.
    matfud

Maybe you are looking for

  • Are my File Vault encrypted files backed up with Time Machine still useful?

    The background: My iMac G5 crashed. It all started one and a half years ago when my screen popped and the frequent hard shutdowns pobably damaged my HDD (the one elegant solution Windows have is the Windows button: press + 'u' + return = proper shutd

  • OSX unexpectedly quits twice in a row

    I installed leopard about a week ago and hadn't had this problem until last night. Yesterday I had my macbook pro on pretty much all day, asleep most of the day. Late last night I was using it, and the screen goes dark from top to bottom and says I n

  • Outlook "lock" on .msg files

    I am trying to confirm what I believe to already be true, if someone can confirm with documentation on this issue: Users are saving Emails as ".msg", if the email/file is opened Outlook "locks" the file. If the email is closed and re-opened moments l

  • IPod Touch Screen Flickering

    I bought two iPod touches (32GB) from the same apple store. When I look at some pages on them the screen has a very faint but noticeable flicker. The flicker is not across the whole screen but only over certain areas. You can see it a lot on the dock

  • How to upload a video on adobe muse cc, if it's not from youtube

    Hi! I have a question about how to upload a video onto my Adobe Muse CC site? The thing is I want to upload it from my computor, not from youtube. I believe it's possible to realize, but I need help to find out how..  Anyone had this kind of question