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();

Similar Messages

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

  • How to download an animated .gif from a web page

    how do i download to my mac an animated gif that is on a web page....when i want a picture or text or something like that i just ...apple shift 4 and "take a picture of it" ...but i want the animation..i have never had to do that on this mac.....a windoze person from the site(chat site) said just right click but my wireless mac mouse doesnt do that....i would appreciate any help.....i do know how to down load from a site that has downloadable .gifs...you just click the download sign they have and no problem....but this is just a random animated .gif from a web page ....i hope my ques is clear....thank you

    Drag and drop it from the webpage onto your desktop. Note that it won't remain "animated" while you're looking at the file's icon, but it should work if you build it into a new website.
    And you can right-click with a Mac mouse - you just have to set it up to do so in System Preferences. (Set the right side of the mouse to be a "secondary click".)
    Matt

  • Can you make an animated gif from edge animate?

    Can you make an animated gif from edge animate?

    not natively. edge exports html and javascript files, not video files, or frames.
    however, you could use a third-party program that has a video screenshot function and make one that way.

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

  • How do I export an animated GIF from Premiere CC?

    How do I export an animated GIF from Premiere CC?
    I dont see an Animated codec option

    Hi Nick
    Believe me I STARTED there.
    I wouldnt post this message if I didnt try there first.
    I do not see Animated GIF as a codec option.
    Please walk me through the step by step process of how you got this.
    Because it is not as obvious as you're making it out to be.
    Further more perhaps a certain format has to be selected for Animated GIF options to appear?
    YES I AM ON CC version too. thanks!

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

  • Animated .gif in HTML article won't upload

    Hello!
    I have an article built with HTML; although largeish and complicated (js, video, blah blah blah), it imports from the Folio panel just fine.....until I put the animated .gifs back into the layout.
    With animated .gifs, the folio panel spins (slowly) at the "building" bar, runs the CPU load up to 50%, and never ever does anything else. (I've left it overnight even.) The web Folio Producer will show an article with an alert: "Corrupt layout. Delete and try adding article again."
    I've made a stripped-down HTML page with a single .gif and it fails just as hard.
    Anyone else noticing this? How do we get this to work? Expensive project is on deadline...
    Thanks!!
    -Miriam

    Please share the folio with [email protected] and let me know what page within what article is causing the crash. I also need to know what version of InDesign is being used, OS and version, what version of the FOlio Builder panel and if you are on CS5 or CS5.5 what version of the digital publishing plug in.

  • Animated gif from flash

    CS4, AS3.Windows XP SP3.
    I've created a pretty simple flash animation with some text that fades in and moves around a bit. Nothing fancy. It runs just fine both locally and on my client's site. I need to turn it into an animated gif so that non-flash viewers will see the animation. But I can't seem to get it to come out right. It needs to have a transparent background and it needs to run just once. Like I said, all that runs fine as an SWF.
    When I choose the export option in the file menu (export movie as gif), it does export and I can run the gif but the background is definitely not transparent and the thing loops continuously. Yes, I've checked the "transparent" checkbox and also set the repetitions to 1. Neither of those settings do anything.
    I also tried "publishing" the gif. That's even worse. The resultant animation doesn't even resemble my SWF. It's a blocky mess when it runs. It does appear to have a transparent background but it loops over and over and again it's a blocky mess (not sure how else to explain that).
    The whole thing is just about 10 layers of different lines of text that are tweened in various ways to get the effect I need.
    You can see the animation on the right hand side of this page: www.ssrights.com. It's the one that says "FREE! Consultation..."
    Hope someone can help.
    Thanks,
    Keith
    PS: The gif is not in place. I currently have it set to just show a static image if someone does not have flash.

    Look, I appreciate that you are making an effot to help, but I hope you realize that most pages like that are just there to attract advertisers. They are mostly nonsense. Filled with fluff and little that's actually helpful. Often copied verbatim from the help file of some application. Not the least bit beneficial. There are tons of "how to" sites out there that say next to nothing and still use a lot of words. I run into them countless times each day. It's beyond irritating when you're trying to learn how to do something. This paragraph on that page you referred me to is a perfect example:
    Set other options for your animated GIF publication. Optimize the color  of the GIF to remove unused colors so that the image size will be  reduced. Set "Dither Solids" so that the colors will be mixed in the  current existing palette. Other options you have to set up are  Interlace, Smooth, and Remove Gradients. Set all of them very well so  that your animated GIF will be published at its best quality.
    Just look at the grammar in the last sentense. It doesn't even make sense and offeres zero useful information. Probably came out of the entirely useless Adobe help system that's fond of defining a term with the term itself.
    Back to the GIF settings. I've chosen nearly every combination of settings on the GIF publish tab. Nothing I do works. The only thing that solved the problem (and it's a crummy solution) was to change the text to a broken apart graphic. I'm sure you are more expert in Flash than I am and so you likely know how to solve this. Have you created a simple example with text and successfully published it as a GIF? You don't even need to tween the text. It can be sitting still on it's own layer and it still fouls things up. If so, what settings are you using to make this work right? That inforamtion would be very helpful!
    Again, is there anyone out there that has specifically dealt with this problem and can offer a specific, viable solution?
    Keith

  • Animated gif to html report

    Hello All
    Is it possible to save an animated GIF to a html report (for publishing to web and still maintain animation)
    Regards
    Ray

    Mike
    Firstly, thanks for showing an interest in my problem.
    I've done some searching here on the forum using keywords like html, animated gif, report etc, but haven't seen anything close to what I want to do.
    I csn save FPs as a whole into a html report, but am unsure where to even begin for an embedded item such as the gif.
    The animated gif was placed on the FP by simply cut and paste and I'm not sure how to go about saving just the gif (sans rest of the FP) to a html report and still maintain the animation properties.
    Regards
    Ray

  • High CPU Consumption when Displaying Animated GIFs

    Hi -
    Within our application we utilize a lot of the standard AJAX loading icons to indiciate that data is downloading/loading. What we've noticed, however, is that when animated GIFs are being displayed they are consuming between 5 and 8 percent of the CPU. I've confirmed it's definitely the GIF that is causing the CPU usage to increase so dramatically.
    Has anyone else experienced this? Do you have work arounds? Does anyone have any idea why performance is so bad on this?
    Does using an SWF instead help?
    Thanks.

    Hello Steve.
    Although I'm not really sure what you mean by "content plugins dialogue", you may be having a problem with some Firefox add-on that is hindering your Firefox's normal behavior. Have you tried disabling all add-ons (just to check), to see if Firefox goes back to normal?
    Whenever you have a problem with Firefox, whatever it is, you should make sure it's not coming from one of your installed add-ons, be it an extension, a theme or a plugin. To do that easily and cleanly, run Firefox in [http://support.mozilla.com/en-US/kb/Safe+Mode safe mode] and select ''Disable all add-ons''. If the problem disappears, you know it's from an add-on. Disable them all in normal mode, and enable them one at a time until you find the source of the problem. See [http://support.mozilla.com/en-US/kb/Troubleshooting+extensions+and+themes this article] for information about troubleshooting extensions and theme. You can troubleshoot plugins the same way.
    If you want support for one of your add-ons, you'll need to contact its author.

  • Import animated GIF from Photoshop?

    I have a question... I am unable to create custom animated gif's in Photoshop 5/6 and import them into Captivate 7.  It just says "The GIF file contains errors".  I've tried exporting on multiple settings and still no luck, same with exporting from Fireworks.
    I am however able to import an exported gif from Flash, yet the quality is horrible and the transparency is buggy.  Is anyone else having this issue, or is there some setting that I am missing?  Basically I need to animate some images within a Captivate project, without the need of using a .SWF (for HTML5 output). Any help would be much appreciated, thank you.

    I experienced this issue with Captivate 8 and Photoshop CC... 
    I eventually realized if the animation has any frames with "no delay" I would get the error.  Changing those frames to a 0.1 second delay resolved my issue.  Not sure if this is the same bug you are experiencing but it's worth a try!

  • Animated gif from .ICO files - Indicates layer is partially locked

    thanks for helping the non-graphics newb out...
    trying to create my first animated gif. I have 8 .ico files that i converted to .png to open them. once all are open i try to combine into one file with 8 layers but am unable to do it!?!? If I click on the main layer in any file it shows as locked and says "Indicates layer is partially locked"

    in any file it shows as locked and says "Indicates layer is partially locked"
    That is normal. Just open the file you want to use as the base/background layer. Now open the file that will be the first layer up from that, press ctrl+a (cmd+a on a mac) to select all of it, then ctrl+c (cmd+c) to copy it. Switch back to the background layer, click in it, then press ctrl+v (cmd+v) to paste it and use the move tool to position it. Repeat for each layer. Note that layers in an animated gif do not play in front of hte base layer the way cartoon cels do, so that you see action in front of a backdrop. You must include everything you want to see at once in each layer.

  • 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

Maybe you are looking for