Problem in loading animated gif

I have problem in loading animated gif with ClassLoader. Here is the code:
ClassLoader loader=this.getClass().getClassLoader();
URL res = loader.getResource(name);
if (res!=null) {
ImageIcon icon = new ImageIcon(res);
if (icon != null) {
Image image = icon.getImage();
if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
images.put(name,image);
return (Image) image;
} else {
System.out.println("Failed to load "+name+" error "+icon.getImageLoadStatus());
images.put(name,"");
Only when the gif is an animated gif, I get error message: Failed to load and icon.getImageLoadStatus() returns 2. Otherwise, it works.
Anyone encounters the same problem as me?

I think the problem is the asynchronous loading of the gif.
when you call f(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
I think it is comming back MediaTracker.LOADING .
for an animated gif, it may not come back COMPLETE until after running thru
the whole automation. instead you could just check:
(icon.getImageLoadStatus() != MediaTracker.ERRORED)

Similar Messages

  • I have a problem with an animated gif.

    I have a problem with an animated gif. When I use text in the
    flash file the gifs text is all messed up. The text was white in
    the flash file but in the gif all the white is splodged all over
    where the text was supposed to be and is totally inelegable.

    OK I found a way around this problem... I delete all the text
    that I had created within Flash and recreated it in Photoshop. I
    rasterized the type in Photoshop the I saved the files as PSD. I
    then went in to Flash and imported them to the library. I place the
    images of the text where they had originally been in my Flash file.
    When I published it as an animated GIF the file was perfect... No
    Black or White blocks...
    SO you might try that... I'm not sure what Flash changed, but
    I used to create text for animiated gif before without any
    problems...

  • Problem to display Animated Gif from HTML into JEditorPane

    I have a problem displaying animated gif that comes from URL (HTML) into JEditorPane.
    Let me show you the source I have:
    * @author Dobromir Gospodinov
    * @version 1.0
    * Date: Dec 6, 2002
    * Time: 6:47:53 PM
    package test.advertserver;
    import javax.swing.*;
    import java.awt.*;
    import java.io.IOException;
    public class Test {
         public static void main(String[] args) {
              JFrame frame = new JFrame();
              JEditorPane ed = new JEditorPane();
              try {
                   ed.setPage("http://localhost:8200/servlet?key=value");
              } catch (IOException e) {
                   e.printStackTrace();
              JPanel panel = new JPanel();
              panel.setPreferredSize(new Dimension(500, 500));
              panel.add(ed);
              frame.getContentPane().add(panel);
              frame.pack();
              frame.setVisible(true);
    }Part of the returned from servlet HTML includes an img tag:
    <img src="/images/MyAnimatedGif.gif" alt="animated gif comment" width="480" height="50"  border="0">Let us assume that MyAnimatedGif.gif has 10 frames and gif is looped - when the 10th is dipslayed it has to display the 1st and so on.
    JEditorPane displays frames from 1 to 10 correctly but does not start from the first again. Instead JEditorPane displays a broken image.
    I locate where the problem arise:
    JEditorPane has an HTMLEditorKit that creates javax.swing.text.html.ImageView instance for every IMG tag.
    And here is the problem:
    ImageView has an ImageObserver necessary for the asynchronous image download. ImageObserver has the imageUpdate method. But this imageUpdate method is never called with ALLBITS flag raised up. Instead, after the last frame of MyAnimatedGif.gif is downloaded the imageUpdate method is called with flag ERROR raised up. Obviously this is a bug of Sun's implementation. Finaly the flag ALLBITS has to be received for normal end of image observing. But ALLBITS flag does not come.
    So, can anybody help me how to load an animated gif within JEditorPane completely.
    Thank You in advance,
    Dobromir Gospodinov
    P.S. If somebody of you wants to debbug what happens within ImageView will have to implement it (and related classes too, because of the limited package visability) borrowing the source from Sun's ImageView.

    I'm also having this problem with java 1.4.1 I discovered that some animated gifs work fine, while others stop animating. Running with java 1.3.1 fixed the problem. I'm going to report this as a bug
    Here's my code:
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    public class AnimatedGifTester
    extends JFrame
    public static void main(String argv[])
    throws Exception
    new AnimatedGifTester();
    public AnimatedGifTester()
    throws Exception
    String[] images = new String[] {
    "http://www.gif.com/ImageGallery/Animated/Animals/Photographic/dog_running.gif",
    "http://www.gif.com/ImageGallery/Animated/Characters/Cartoon/java.gif",
    "http://www.webdeveloper.com/animations/bnifiles/anielg.gif",
    "http://www.webdeveloper.com/animations/bnifiles/cat2.gif",
    "http://images.animfactory.com/animations/animals/fish/big_fish_swimming_md_wht.gif",
    "http://www.webgenies.co.uk/images/martian.gif",
    "http://www.webdeveloper.com/animations/bnifiles/at_sign_rotating.gif",
    "http://www.webdeveloper.com/animations/bnifiles/arrow_1.gif",
    "http://www.gif.com/ImageGallery/Animated/Characters/Cartoon/javaacro.gif",
    "http://java.sun.com/products/java-media/2D/samples/suite/Image/duke.running.gif",
    "http://www.gif.com/ImageGallery/Animated/SouthPark/Cartoon/stan.gif"
    StringBuffer buffer = new StringBuffer("<html><body>");
    for (int idx = 0; idx < images.length; idx++)
    buffer.append("<img src='" + images[idx] + "'>");
    buffer.append("</body></html>");
    String html = buffer.toString();
    // save a copy of the html to open in a browser so we can see what it's
    // supposed to look like
    BufferedWriter writer = new BufferedWriter(new FileWriter("animatedGifTest.html"));
    writer.write(html);
    writer.close();
    JEditorPane editorPane = new JEditorPane("text/html", html);
    editorPane.setEditable(false);
    getContentPane().add(editorPane);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(new Dimension(400, 600));
    show();

  • Problems/help with animated GIF exports

    I am an experienced Photoshop user.  I recently upgraded to CS5 (Windows) and have been attempting to produce animated gif files. 
    After reading a few tutorials on the topic, I have been able to: 
    Create a PSD with a few jpg images as layers; 
    Move the layers to the animation window; 
    Set the cycle times and optimize the animation window; and, 
    Use the Save for Web Devices dialog to create the GIF file. 
    Everything appears to be normal throughout this process.  However, the exported GIF file appears as a dark gray frame when I open it in IE, or upload it to my image hosting site. 
    Anybody else experiencing this type of problem? 
    Thanks 

    No, my Photoshop CS5 saves animated GIFs just fine, and I did just what you said.  For example (you have to click on an image here to see it animate):
    Can you post your image here?  Maybe it could be a problem with your browser not animating the image properly?  What version of IE do you use?
    -Noel

  • Problem to create animated gif using transparent frames

    Hi, everyone:
    My name is Edison, I am playing with Gif89Encoder utility classes to make an animated gif which is a requirement for my course work.
    I got some problem about the transparent frames. I used the png image as the frame to create the animated gif,
    those pngs have transparent colors and the background is totally transparent, when i create the animated the gif with those
    frames, the animated gif display the colors but without transparency for those colors, but the background is transparent as expected.
    I am not sure if I should IndexGif89Frame or DirectGif89Frame for the colors from the Gif89encoder package.
    Is there anyone got the same problem and knows how to fix it?
    The following is how i setup the colors in my png file, the alpha channel is 80.
    Color[] colours = new Color[7];
              colours[0] = new Color(255, 255, 255, 0);
              colours[1] = new Color(128, 128, 255, 80);
              colours[2] = new Color(128, 0, 128, 80);
              colours[3] = new Color(0, 128, 128, 80);
              colours[4] = new Color(128, 128, 0, 80);
              colours[5] = new Color(204,102,255,80);
              colours[6] = new Color(255, 0, 0, 80);The code i did to generate gif:
    public void run89Gif()
            Image[] images = new Image[4];    
            try{
                images[0] = ImageIO.read(new File("D:/temp/0.png"));
                images[1] = ImageIO.read(new File("D:/temp/1.png"));
                images[2] = ImageIO.read(new File("D:/temp/2.png"));
                images[3] = ImageIO.read(new File("D:/temp/3.png"));
                OutputStream out = new FileOutputStream("D:/temp/output.gif");
                writeAnimatedGIF(images,"Empty annotation", true, 1, out);         
                images = null;
            }catch(IOException er){ }
    static void writeAnimatedGIF(
            Image[] still_images,
                String annotation,
                boolean looped,
                double frames_per_second,
                OutputStream out) throws IOException
            Gif89Encoder gifenc = new Gif89Encoder();
            for (int i = 0; i < still_images.length; ++i){
               gifenc.addFrame(still_images);
    gifenc.setComments(annotation);
    gifenc.setLoopCount(looped ? 0 : 1);
    gifenc.setUniformDelay((int) Math.round(100 / frames_per_second));
    gifenc.encode(out);
    Thanks in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Hi, everyone:
    My name is Edison, I am playing with Gif89Encoder utility classes to make an animated gif which is a requirement for my course work.
    I got some problem about the transparent frames. I used the png image as the frame to create the animated gif,
    those pngs have transparent colors and the background is totally transparent, when i create the animated the gif with those
    frames, the animated gif display the colors but without transparency for those colors, but the background is transparent as expected.
    I am not sure if I should IndexGif89Frame or DirectGif89Frame for the colors from the Gif89encoder package.
    Is there anyone got the same problem and knows how to fix it?
    The following is how i setup the colors in my png file, the alpha channel is 80.
    Color[] colours = new Color[7];
              colours[0] = new Color(255, 255, 255, 0);
              colours[1] = new Color(128, 128, 255, 80);
              colours[2] = new Color(128, 0, 128, 80);
              colours[3] = new Color(0, 128, 128, 80);
              colours[4] = new Color(128, 128, 0, 80);
              colours[5] = new Color(204,102,255,80);
              colours[6] = new Color(255, 0, 0, 80);The code i did to generate gif:
    public void run89Gif()
            Image[] images = new Image[4];    
            try{
                images[0] = ImageIO.read(new File("D:/temp/0.png"));
                images[1] = ImageIO.read(new File("D:/temp/1.png"));
                images[2] = ImageIO.read(new File("D:/temp/2.png"));
                images[3] = ImageIO.read(new File("D:/temp/3.png"));
                OutputStream out = new FileOutputStream("D:/temp/output.gif");
                writeAnimatedGIF(images,"Empty annotation", true, 1, out);         
                images = null;
            }catch(IOException er){ }
    static void writeAnimatedGIF(
            Image[] still_images,
                String annotation,
                boolean looped,
                double frames_per_second,
                OutputStream out) throws IOException
            Gif89Encoder gifenc = new Gif89Encoder();
            for (int i = 0; i < still_images.length; ++i){
               gifenc.addFrame(still_images);
    gifenc.setComments(annotation);
    gifenc.setLoopCount(looped ? 0 : 1);
    gifenc.setUniformDelay((int) Math.round(100 / frames_per_second));
    gifenc.encode(out);
    Thanks in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Problem with importing animated gifs

    Hi i'm trying to use an animated gif in my project. Basically my after effects project is just a countdown from 10 to 0 while the animated gif spins continuously during the countdown. My problem is when I use the animated gif the background it is no longer transparent and the background is instead white. How do I make it transparent again in after effects? Next the animated gif is about a 2 second loop, it won't let me drag the bars to extend the time to 10 seconds. How do I loop it for 10 seconds?
    These aren't musts, but if anyone could, help would be greatly appreciated:
    1) For the text effect 'numbers' (which I used for the countdown effect) it always renders really shaky and bouncy when i preview it. Is that normal?
    2) It has the time as 00:00:00:00 (type: timecode 30). How do I make so it only shows 00:00 ?
    Any help would be awesome.
    Thank you

    My problem is when I use the animated gif the background it is no longer transparent and the background is instead white.
    Correct. As a conmpositing program, AE requires proper Alpah transparency, not palette-based transparency. File must be converted to an image sequence with Alpha channel.
    Next the animated gif is about a 2 second loop, it won't let me drag the bars to extend the time to 10 seconds. How do I loop it for 10 seconds?
    Footage interpretation --> Loops
    1) For the text effect 'numbers' (which I used for the countdown effect) it always renders really shaky and bouncy when i preview it. Is that normal?
    Yes, it's normal if you are using a non-monospaced font. Use a suitable font.
    2) It has the time as 00:00:00:00 (type: timecode 30). How do I make so it only shows 00:00 ?
    Use multiple layers and effects and mask them out.
    Mylenium

  • Problem exporting as animated gif in cs3

    i'm setting it to publish as animated gif, setting the
    options i want in the publish settings pop up under 'gif' - but it
    just keeps giving me a single frame image.
    am i missing something?

    i am having this exact same problem with a 125 (i think)
    frane long short animation imade recently. when i publish it to gif
    it only does 1 fram and not the rest so the animation is lost.
    please help a.s.a.p =]

  • 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..........

  • Problems only with Adobe ImageReady Animated GIF

    Anyone encounter a problem and solution for getting ImageReady animated GIF working properly in a java app? Developer placed 2 animated gifs in the app which caused the CPU system resources to spike to 100%.
    We then tested animated GIFs made from Macromedia Flash and also a freeware animated GIF editor, and both work out fine in the same java app.
    It's odd, but we think there's a problem specifically with animated GIFs produced by Adobe's Image Ready in the Creative Suite 1 package.
    Anyone have more insight?

    Its been a long time since I have used ImageReady, and then it was for about year when CS3 came out. So my memory if very rusty with that program. (In other words I am hoping that I am not too far off base, lol.)
    Check and make sure there are the same number of layers as there are frames. I believe there is an option in the animation palette for sending the frames to layers. Once you know that the frames and layers match (plus any additional layers you create), you can clear out the animation and reapply the layers to frames.
    You should find a small icon in the upper right hand corner of the animation palette and the layers palette. Clicking them will bring up a menu that will do what you need.

  • Quality problem with animated gif through flash

    i got a problem with making animated gif through flash.
    on html/swf publication it looks clear.
    but the weird thing is through gif publication, it wouldn't show. and exporting it as a movie as gif cause visual defect when put up on web.
    it looks better when you open it in a browser.
    this is how it looks for a profile gif in thumbnail mode. blocky and unclear.
    how do you get it to look good both in thumbnail mode and in browser mode. i seen other that have a clear gif in thumbnail mode.  are my setting wrong for flash? or should i just do gif in photshop instead. i heard rumors flash don't do gif very well.

    Change your gif export setting under publish...
              Dimensions         : Match movie
              Playback             : Animated
                                        : Loop continuously
              Options               : Optimize colors
                                        : Smooth
              Transparent         : Opaque
              Dither                 : None
              Palette Type       : Adaptive
              Max colors         : 99999

  • Safari 4: Problems with animated GIF

    Hi,
    since I've updated to Mac OS X 10.6 my Safari 4.0.3 has Problems with some animated GIF.
    Some of these smileys look strange.
    OS: Mac OS X 10.6.1
    Mac: iMac (24-inch Early 2008)

    HI,
    Apparently you aren't alone.
    http://discussions.apple.com/thread.jspa?messageID=10059219&#10059219
    Carolyn

  • Animated gif jerky in Safari 7

    I have a website with a page-loading animated gif, which stutters badly the first time a page is loaded. In subsequent re-loadings of the page the gif animation is smooth. This problem only occurs in Safari 7.0.1, not other browsers. In fact before I upgraded to Mavericks, it worked fine on Safari, too (Mountain Lion). Please help.

    I also noticed this today, and it seems that for some reason the frame rate of animated GIFs is limited to 10 frames per second, or a minimum delay of 100msec per frame. This animation should loop every second: http://www.dr-lex.be/tmp/Rotation1Sec.gif
    In Firefox it behaves correctly, but if you time it in Safari, you'll see that it takes 5 seconds per loop, because it has 50 frames.
    By the way, QuickTime Player can also play GIF animations and it plays them at the correct speed.
    It appears this bug is not in Safari itself, but somewhere deeper in some framework. The bug ID is 5815212.

  • Will there ever be a fix for Animated Gifs  OS 10.5.8

    I realize this extremely stupid bug which has/had been around for many years was apparently fixed in 10.6, but that upgrade is simply not an option for me (as, 10.6 will not install on this machine.)
    the problem is very well known (and many years old): loading a simple animated gif, even very small files, causes Safari to beachball while the gif is downloading (this can take over a minute even for a file under 250k). it should be almost instant (like it is in Firefox)
    this was never a problem using older OS and older versions of Safari (even very large animated gifs loaded very quickly and did not affect system performance.)
    this problem does not exist (and never did exist) in Firefox. i can load animated gif as expected, and very quickly under firefox.
    why did apple refuse to fix this? why do they continue to refuse? it worked fine, and then apple broke it. and it seems like they are leaving it broken on purpose.

    HI,
    Empty the Safari Cache from the Safari Menu Bar more often.
    Go to the Safari Menu Bar, click Safari/Preferences. Make note of all the preferences under each tab. Quit Safari. Now go to ~/Library/Preferences and move this file com.apple.safari.plist to the Desktop.
    Relaunch Safari and see if that makes a difference. If not, move the .plist file back to the Preferences folder. If Safari functions as it should, move that .plist file to the Trash.
    Carolyn

  • Animated Gif won't stop looping!

    I'll try to format my question as best I can.
    I have created a Java chat applet, and for the Java chat, I have created a "ChatPane" class for displaying the chat. ChatPane is an extension of Canvas, and every time the paint() method is called, the program loops through visible lines of text drawing them on a buffer image, then draws the buffer on the screen.
    My problem lies in animated gifs. In my chatroom, chatters can type textual symbols that will be replaced with an image (or emoticon). I have created my animated icons in a popular animated gif editing program, and I have set particular icons to loop 3 times. The problem is that when the animated icon is displayed in my applet, the animation -doesn't stop- after 3 loops, it loops forever! I can't for the life of me figure out why! Can anyone provide any insight as to why the animations won't stop after 3 loops? The animations work just fine if displayed in a browser by themselves (they stop looping after 3 times)
    Thank you for any help!
    [email protected]
    Tony N.

    From what I understand of your problem;
    - You have made your own animated gifs
    - With the software to make these gifs you have set them to loop their animations 3 times
    - They loop continuously
    I don't see how java can be expected to interpret the animated gif software instructions to loop only 3 times and would assume that there are various proprietry ways of setting this (an assumption based on applets /javascript etc, that rely on the client-side browser interpreter). So, if you loop your animated gif or have any form of animated gif that you import into your program with getDocumentBase /getCodeBase as a (pre-animated) gif, then this is exactly what I would assume would happen.
    The answer is to seperate your images with eg;-
    smiley1[0];
    smiley1[1];
    smiley1[2];
    run a seperate thread, cycle through them as you wish and stop.
    I'm fairly sure that there is nothing in either the swing libraries or the jmf libraries that can resolve this any other way, so your choices are write extra code and have a pool of threads to control this, or leave it as is.

  • Animation /animated gifs

    hi all
    i was trying to use animated gifs in a game. The problem comes when I run the animated gif. The previous images of the gif remain on the screen. When I use any imaging software to view the animated gif it comes up correctly. My first question is it a problem with my animated gif or do I need to do something in Java. if the answer is I need to do something in java, could someone please help and tell me what I need to do.

    you could of always said.....
    save the animated gifs as individual gifs and cycle through them in the code?
    probably been easier, no?

Maybe you are looking for

  • Windows 8 compatibility for x300?

    Somewhat basic question, but I can't find any info on whether I can run Windows 8.1 on my x300 laptop. The Windows Upgrade Assistant only seems to tell me what existing software can run, but I just need to know if the laptop will even run Win 8. The

  • Spiller box for mini display port

    I need to get 2 screens working from my 2011 imac. The screens are hdmi I have a mini display/thunderbolt to hdmi cable and works fine on one screen but I've tried various hdmi splitter boxes but they won't see the mini display to hdmi cable.  Cheers

  • After installed iPhoto upgrader tool, photos software is still asking for IPhoto needs to be update, why?

    MAC OSX :- 10.10.3 IPHOTO :- 9.6 I have recently updated my os x 10.10.2 to 10.10.3 and found iPhoto software dose'nt work. there is some other application appears called photos like iPhone,when i am trying to open it, asking to marge iPhoto library.

  • Optimizer choosing different plans when ROWNUM filter. [UPDATED: 11.2.0.1]

    I'm having a couple of issues with a query, and I can't figure out the best way to reach a solution. Platform Information Windows Server 2003 R2 Oracle 10.2.0.4 Optimizer Settings SQL > show parameter optimizer NAME                                 TY

  • Function module to read Purchase Requestions

    Hi all, As you must be knowing that  in /SAPAPO/RRP3  transaction we can create the Purchase Requisitions. Now my requirement is that I want to read all the Purchase Requisitions from today onwards for all product and location combination. Please sug