Animated gif resizing problem

Im trying to achieve the following: showing an animated gif that resizes to fill the area of a canvas. I tried the easy way: adding a label and setting the icon for that label, but when trying to resize the image it doesnt show (see code below). Is there any particular way of resizing an animated gif? can the labe-icon approach be used with animated gif that must be resized?
Thanks a lot in advance.
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import javax.swing.ImageIcon;
public class TestFrame extends javax.swing.JFrame {
/** Creates new form TestFrame */
public TestFrame() {
initComponents();
Image image = this.getToolkit().getImage("C:\\multivideo\\img\\39.gif");
Dimension dim = jLabel1.getPreferredSize();
image = image.getScaledInstance(dim.width, dim.height, Image.SCALE_SMOOTH);
ImageIcon i = new ImageIcon(image);
jLabel1.setIcon(i);
jLabel1.setBackground(Color.BLUE);
pack();
/** This method is called from within the constructor to
* initialize the form.
private void initComponents()
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setIcon(new javax.swing.ImageIcon("C:\\multivideo\\img\\40.gif"));
jLabel1.setMaximumSize(new java.awt.Dimension(1436, 86));
jLabel1.setMinimumSize(new java.awt.Dimension(1436, 86));
jLabel1.setPreferredSize(new java.awt.Dimension(1436, 86));
getContentPane().add(jLabel1, java.awt.BorderLayout.CENTER);
pack();
* @param args the command line arguments
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TestFrame().setVisible(true);
private javax.swing.JLabel jLabel1;
}

I don't think getScaledInstance is smart enough to return a scaled image.
You could try doing your own scaling:
import java.awt.*;
import java.awt.geom.*;
import java.net.*;
import javax.swing.*;
public class Animated extends JComponent {
    private Image image;
    private double scale;
    public Animated(URL url, double scale) {
        image = new ImageIcon(url).getImage();
        this.scale = scale;
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Insets insets = getInsets();
        Graphics2D g2 = (Graphics2D) g.create();
        g2.translate(insets.left, insets.top);
        g2.scale(scale, scale);
        g2.drawImage(image, 0, 0, this);
        g2.dispose();
    public Dimension getPreferredSize() {
        Insets insets = getInsets();
        int w = insets.left + insets.right + (int)(scale*image.getWidth(null));
        int h = insets.top + insets.bottom + (int)(scale*image.getHeight(null));
        return new Dimension(w,h);
    public static void main(String[] args) throws MalformedURLException {
        URL url = new URL("http://members.aol.com/royalef/sunglass.gif");
        final JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new Animated(url, 2), BorderLayout.NORTH);
        f.getContentPane().add(new Animated(url, 1), BorderLayout.SOUTH);
        f.pack();
        SwingUtilities.invokeLater(new Runnable(){
            public void run() {
                f.setLocationRelativeTo(null);
                f.setVisible(true);
}Or you could explicitly extract the images from the animated gif and
resize them individually. The sample code here does the extraction:
http://forum.java.sun.com/thread.jspa?forumID=20&threadID=500348

Similar Messages

  • Animated Gif Color Problem

    Hi all,
    I want to make a small animated gif by My lovely software : AfterEffect...
    The problem i face, that when i render my work, i get an animated gif with bad colors (like if i export as 256 colors for example..)
    I put in the export setting MILLIONS OF COLORS ....
    and i get always POOR color depth ...
    I can see the true colors in the After Effect work Panels ...
    Only when i put the composition in the render queu and export as Animated Gif, i get the Poor colors..
    PLEASE HELP ME ...
    Thanks

    As pointed out by the others, the limitation is in the file format. You will never exceed the 256 barrier. This is further complicated by how AE determines the color palette. This usually happens on the first few frames, 'cos naturally the other frames do not exist and AE doesn't know about them. If there is considerable change in the color palette over time, this cannot be accommodated. Therefore you'd really do a lot better by following the advise provided by the others. In addition to Rick's tips, I recommend you work with the perceptive dithering mode when saving your GIFs. This usually gives the "smoothest" result, but may shift the colors ever so slightly. I also recommend to not use transparencies with animated GIFs. They have a severe impact on file size and compression quality as well as possibly the playback performance in your browser. If you know the background color of your web page, it should be part of the file.
    Mylenium

  • Animated Gif on problems when published

    Hi, Can anyone help?
    I've imported an animated gif and used it on my stage but
    when I publish it it doesn't work on a webpage and says that the
    Gif is missing.
    Does anyone know how to solve this problem?
    Thanks

    Hi, Can anyone help?
    I've imported an animated gif and used it on my stage but
    when I publish it it doesn't work on a webpage and says that the
    Gif is missing.
    Does anyone know how to solve this problem?
    Thanks

  • Animated GIF loop problem

    I have created a simple roll over effect using an animated
    GIF over 10 frames in Fireworks which increases the fill opacity of
    a button on mouse over. I set the loop to 1 so that the animation
    will play the 10 frames and then stop, but when i export to
    Dreamweaver and preview in browser the loop will not stop.

    I think this is an oversight in functionality.
    I also was never able to get the 'stop' to work.
    h

  • Identifying/resizing animated GIF

    Hi
    This is my situation: I load user-selected image files (any format is OK, the more the better) for later transmission as byte array, always re-encoded as JPG. If the image is over some certain width/height, I scale down the image (display size issues). Until now I was reading the images with ImageIO.read, downsizing with Graphics2D.drawImage and encoding with ImageIO.write, and everything works nicely.
    Now I need to support animated GIFs as well. The current method makes animated gifs as a static first frame of the animation. My two alternatives are:
    1 - support animated GIF downsizing
    2 - detecting animated GIFs and handling them separately (no resize allowed, no re-encode)
    The first alternative sounds cumbersome, Googling around showed problems with lost transparency and requiring to downsize all frames separately and then re-encode. If I have to do this extract-downsize-encode I won't take this route, better do not perform animated GIF resizing. The second alternative sounds much simpler, and less problem-prone.
    Now I would like suggestions on how can I archive this. I'd really appreciate some code/lib to detect and optionally resize animated GIFs. It must be a free code solution.
    The only animated GIF detection code I found was this, but it requires looking for certain bytes, and I'd like a more robust solution (also it didn't worked).
    I would like to keep using ImageIO API rather than older APIs, as it seems to provide better image format support and is way simpler. A lib to do the GIF part of the job is fine.
    Thanks!

    This is my situation: I load user-selected image files (any format is OK, the more the better) for later transmission as byte array, always re-encoded as JPG. If the image is over some certain width/height, I scale down the image (display size issues).If they are JPEGs that is entirely the wrong solution. You are losing far too much image quality. What you should be doing here is saving with a lower 'q'. That's exactly what it's for - intelligent compression of images. You are just doing naive resampling. JPEG can do far better than that.
    I worked on a project where somebody downsized thousands of images like this, entirely the wrong way. Don't repeat this mistake.
    As to the rest, sounds like you need a GIF plugin for ImageIO that will let you read the header.

  • Resized animated gif ImageIcon not working properly with JButton etc.

    The problem is that when I resize an ImageIcon representing an animated gif and place it on a Jbutton, JToggelButton or JLabel, in some cases the image does not show or does not animate. More precicely, depending on the specific image file, the image shows always, most of the time or sometimes. Images which are susceptible to not showing often do not animate when showing. Moving over or clicking with the mouse on the AbstractButton instance while the frame is supposed to updated causes the image to disappear (even when viewing the non-animating image that sometimes appears). No errors are thrown.
    Here some example code: (compiled with Java 6.0 compliance)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test
         public static void main(String[] args)
              new Test();
         static final int  IMAGES        = 3;
         JButton[]           buttons       = new JButton[IMAGES];
         JButton             toggleButton  = new JButton("Toggle scaling");
         boolean            doScale       = true;
         public Test()
              JFrame f = new JFrame();
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel p = new JPanel(new GridLayout(1, IMAGES));
              for (int i = 0; i < IMAGES; i++)
                   p.add(this.buttons[i] = new JButton());
              f.add(p, BorderLayout.CENTER);
              f.add(this.toggleButton, BorderLayout.SOUTH);
              this.toggleButton.addActionListener(new ActionListener() {
                   @Override
                   public void actionPerformed(ActionEvent e)
                        Test.this.refresh();
              f.setSize(600, 300);
              f.setVisible(true);
              this.refresh();
         public void refresh()
              this.doScale = !this.doScale;
              for (int i = 0; i < IMAGES; i++)
                   ImageIcon image = new ImageIcon(i + ".gif");
                   if (this.doScale)
                        image = new ImageIcon(image.getImage().getScaledInstance(180, 180, Image.SCALE_AREA_AVERAGING));
                   image.setImageObserver(this.buttons);
                   this.buttons[i].setIcon(image);
                   this.buttons[i].setSelectedIcon(image);
                   this.buttons[i].setDisabledIcon(image);
                   this.buttons[i].setDisabledSelectedIcon(image);
                   this.buttons[i].setRolloverIcon(image);
                   this.buttons[i].setRolloverSelectedIcon(image);
                   this.buttons[i].setPressedIcon(image);
    Download the gif images here:
    http://djmadz.com/zombie/0.gif
    http://djmadz.com/zombie/1.gif
    http://djmadz.com/zombie/2.gif
    When you press the "Toggle scaling"button it switches between unresized (properly working) and resized instances of three of my gif images. Notice that the left image almost never appears, the middle image always, and the right image most of the time. The right image seems to (almost) never animate. When you click on the left image (when visble) it disappears only when the backend is updating the animation (between those two frames with a long delay)
    Why are the original ImageIcon and the resized ImageIcon behaving differently? Are they differently organized internally?
    Is there any chance my way of resizing might be wrong?

    It does work, however I refuse to use SCALE_REPLICATE for my application because resizing images is butt ugly, whether scaling up or down. Could there be a clue in the rescaling implementations, which I can override?
    Maybe is there a way that I can check if an image is a multi-frame animation and set the scaling algorithm accordingly?
    Message was edited by:
    Zom-B

  • 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

  • Keynote 3: Transparent Animated GIF Problems

    I've been trying to get an animated GIF with a transparent background to run in Keynote, but it's giving some disastrous results.
    I produce the animation by rendering the frames as PNG (with alpha channel) in MegaPOV 1.2.1. Then I use the convert utility from ImageMagick 6.2.9 to make them into an animated GIF.
    When I drop the animated GIF into Keynote 3.0.2, the first frame shows fine (with transparency and all). But when I animate it, the background goes red (the main color in this particular movie) and some trace of the previous frames stays. It seems like:
    1. Rather than displaying the GIF frame-by-frame, each frame is getting layered onto the previous frames.
    2. Keynote doesn't like the alpha channel for some reason.
    Problem 1 is also present if I open the GIF in Preview (is that supposed to be the correct behavior of an animated GIF?). Problem 2 seems to be Keynote-specific.
    Any suggestions for a work-around on this? The animated GIFs work fine if rendered without the alpha channel, but it'd look so much better with transparency!
    iMac 2GHz Intel Core 2 Duo   Mac OS X (10.4.9)  

    MegaPOV doesn't have a GIF output option. The choices are PNG, Targa, PPM, and hdr (not familiar with that last one). I don't know if PPM even has alpha-capability.
    So in some way, I have to convert PNG to GIF. The tools I have to do this are ImageMagick and Gimp. I tried them both, then viewed the results using several programs. Results are tabulated below -- (1) means that problem 1 from above was apparent (ie, parts of the previous frames were visible under the current frame); (2) means that problem 2 was visible (ie, the transparent parts took on some background color).
    If I didn't know how to change the default white background in the program, I couldn't tell whether problem (2) occurred, since the movie made with Gimp had a white background in Keynote.
    Using ImageMagick 6.2.9 to convert PNG->GIF and animate GIF:
    * viewing with Safari 2.0.4 : (1), can't tell for (2)
    * viewing with Preview 3.0.9 : (1), can't tell for (2)
    * viewing with Firefox 2.0.0.3 : (1)
    * viewing with Keynote 3.0.2 : (1), (2) -- alpha goes red
    Using Gimp 2.2.11 to convert PNG->GIF and animate GIF:
    * viewing with Safari : (1), can't tell for (2)
    * viewing with Preview : (1), can't tell for (2)
    * viewing with Firefox : (1)
    * viewing with Keynote : (1), (2) -- alpha goes white
    I only converted the first few frames using Gimp, since I was doing it by hand.
    All of this makes me wonder whether I'm dreaming the impossible, since problem (1) is universally present. It also makes me pretty sure that problem (2) is Keynote-specific.
    If there are any other tools that will convert/animate GIFs on a modern Mac, I'd love to hear about them. My UNIX-y tools seem to be failing me here. The Mac tools I remember from "back in the day" -- GIFBuilder and GIFConverter -- seem to have been abandoned around the beginning of Mac OS X. GIFBuilder won't even load my files, and GIFConverter still lacks alpha support in PNG.

  • Problem saving animated gif

    Hello!
    Just for fun i was planning to edit a animated football tackle gif. I was planning to remove the player who tackle in each and every frame of the animated gif. So it would take some time to finish.
    I have successfully opened the gif in CS6 via import Video Frames to Layers.
    It consists of 72 layers and i have tried to fix 10 of them just to see how it roughly would look like.
    My problem comes when I try to save and render the GIF (via save for WEB).
    The 10 first frames of my gif only shows one freezing frame, and then it shows the rest from 11-72 without any problems.
    What am i doing wrong, since my edited layers don't show up in the final GIF?

    Right on! Easy solution.
    First, the reason your first 10 frames are not changing is because each of those frames shows the same layer (Layer 1).
    In your layers panel, you have Layer 1 set to visible and all the other layers are invisible. That's good for Frame 1, but for frame 2 you'll want to make Layer 2 the visible one.
    Click on Frame 2 in your Timeline panel and then check the eyeball icon to make Layer 2 visible! Do the same for Frame 3/Layer 3, Frame 4/Layer 4, etc. until you get to the end of the animation!
    To address the second problem, the option for Make Frames from Layers is greyed out because you already have frames in your timeline.
    Go to your Timeline panel and select all the frames and delete them.
    Then select all your layers in the Layer panel, right-click and choose Make Frames from Layers... you should be able to click on it once your Timeline is cleared. It will automatically create frames that go from Layer 1 to your last layer (so, you wouldn't have to do it manually like above ^).
    Either way should take care of your problem! Please let me know if this works for you!!
    Cheers,
    Michael

  • Animated Gif Problem

    Greetings
    I would appreciate some help.
    I am new at creating animated gif's, and am experiencing a
    problem with them when I try to view them in a browser.
    I am working in Fireworks 2004, the following is what I do.
    Create first frame.
    Insert simple arrow.
    Create second frame
    Insert simple arrow with diffrent color
    Third frame same but diffrent image.
    Set the Optimize Panel to Animated Gif, transparency set to
    No tranparency.
    Click on File, Export.
    Type the name of the file in File Name box.
    Select "Frames to Files" option for Save as type option.
    In my folder where I saved the files there are now three gif
    files.
    When I open the file into the following browsers IE 7, 6.0 or
    Firefox it remains as a static image in the browser with no
    animation, the same is for viewing it in Window Explorer Preview
    Pane.
    In Fireworks however the animation plays perfectly.
    I would really appreciate it if someone could tell me what I
    am doing wrong or why they created animated gifs are not playing in
    the browser.
    Regards
    Dave

    Instead of Frames to files on export, select Images only.
    that should do it -
    alex
    revbear wrote:
    > Greetings
    >
    > I would appreciate some help.
    >
    > I am new at creating animated gif's, and am experiencing
    a problem with them
    > when I try to view them in a browser.
    >
    > I am working in Fireworks 2004, the following is what I
    do.
    >
    > Create first frame.
    > Insert simple arrow.
    > Create second frame
    > Insert simple arrow with diffrent color
    > Third frame same but diffrent image.
    >
    > Set the Optimize Panel to Animated Gif, transparency set
    to No tranparency.
    >
    > Click on File, Export.
    > Type the name of the file in File Name box.
    > Select "Frames to Files" option for Save as type option.
    >
    > In my folder where I saved the files there are now three
    gif files.
    >
    > When I open the file into the following browsers IE 7,
    6.0 or Firefox it
    > remains as a static image in the browser with no
    animation, the same is for
    > viewing it in Window Explorer Preview Pane.
    >
    > In Fireworks however the animation plays perfectly.
    >
    > I would really appreciate it if someone could tell me
    what I am doing wrong or
    > why they created animated gifs are not playing in the
    browser.
    >
    > Regards
    > Dave
    >
    >

  • Animated GIF problem saving for web in CS6

    I made an animated gif in CS6 and trying to save it for the web. The duration of the animation is pretty long, about 44 seconds. After 17 seconds the animation stops while the saving was completed. How can I solve this problem? The file is too large to attach (725 x 225 px) unfortunately.
    Please give me some advice;-)

    Yopu probably exceed the GIF specs and generate too many frames.
    How many frames are possible?

  • Animated gif and page refresh problem

    Animated gif and page refresh problem
    Hi There,
    I'm trying to build a simple "Please wait......" screen using jsp and javascript.
    So far all is going well except that my animatate gif keeps refreshing everything the page is refresh.
    Is there a way the i can prevent the body of the page from refreshing?
    below is my sample code:
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <jsp:useBean id="StatusBean" class="com1.CandidateRelease" scope="session"/>
    <html>
    <script LANGUAGE="JavaScript">
    function refresh()
    <% if (StatusBean.isRunning()) { %>     
         //setTimeout("refresh()", 1000);
         setTimeout("location='status.jsf'", 1000);
    <% }else{%>
         window.location= "busStopAdmin.jsf";
    <%} %>
    </script>
    <head>
         <script LANGUAGE="JavaScript">     
              refresh();
         </script>     
    </head>
    <body>
         <img id="myImage" src="../img/ojp_wait.gif" alt="" width="151" height="36">
    </body>
    </html>

    Animated gif and page refresh problem
    Hi There,
    I'm trying to build a simple "Please wait......" screen using jsp and javascript.
    So far all is going well except that my animatate gif keeps refreshing everything the page is refresh.
    Is there a way the i can prevent the body of the page from refreshing?
    below is my sample code:
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <jsp:useBean id="StatusBean" class="com1.CandidateRelease" scope="session"/>
    <html>
    <script LANGUAGE="JavaScript">
    function refresh()
    <% if (StatusBean.isRunning()) { %>     
         //setTimeout("refresh()", 1000);
         setTimeout("location='status.jsf'", 1000);
    <% }else{%>
         window.location= "busStopAdmin.jsf";
    <%} %>
    </script>
    <head>
         <script LANGUAGE="JavaScript">     
              refresh();
         </script>     
    </head>
    <body>
         <img id="myImage" src="../img/ojp_wait.gif" alt="" width="151" height="36">
    </body>
    </html>

  • Animated GIF problems

    I've recently implemented an extension of IconView to animate gifs correctly in editor panes. I am just haveing two problems with it that I can't figure out.
    Firstly, when an animated gif is added it animates fine. The next time the same gif is added, it doesn't animate, just shows the last image of the animation. I assume that something is trying to be clever by caching the image somewhere, is there any way around this?
    Secondly some of the gifs do not animate very well. I believe that they may be using transparency to leave the contents of previous frames behind, but I guess that java does not support this. Any thoughts on how I could solve this?
    Here is the simple code for my view:
    class AnimatedIconView extends IconView implements ImageObserver
         private Container container = null;
         private Rectangle bounds = null;
         public AnimatedIconView(Element e)
              super(e);
              Icon icon = StyleConstants.getIcon(getAttributes());
              if (icon instanceof ImageIcon)
                   ((ImageIcon)icon).setImageObserver(this);
         public void setParent(View parent)
              super.setParent(parent);
              container=getContainer();
         public void paint(Graphics g, Shape s)
              super.paint(g,s);
              bounds=s.getBounds();
         public boolean imageUpdate(Image img,int infoflags,int x,int y,int width,int height)
              if (((infoflags & ImageObserver.FRAMEBITS)>0)&&(container!=null)&&(bounds!=null))
                   container.repaint((int)bounds.getX(),(int)bounds.getY(),(int)bounds.getWidth(),(int)bounds.getHeight());
              return true;
    }Dave

    I just can point you the bug which is probably related to your problem:
    http://developer.java.sun.com/developer/bugParade/bugs/4725530.html

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

  • Problems playing animated gif on label again

    I have program that is displaying a graphic representation of a wave file this is a cut down of it. I am using a mouse listener to detect the mouse wheel and from that I am zooming in on the wave graphic or zooming out.
    The problem is when I zoom in a Jlabel is displayed with an animated gif saying �zooming in� that work fine. But as soon as I zoom in again, the Jlabel will not display the image again or the zooming out image.
    I an new to java so be kind to my code
    Any help would be greatly appreciated
    CODE
    * DisWav1.java
    * Created on 30 April 2006, 14:43
    import java.awt.BasicStroke;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.geom.Line2D;
    import java.util.Vector;
    import javax.swing.JPanel;
    import javax.swing.JDialog;
    public class DisWav1 extends JDialog implements Runnable{
    // varables
         private Thread thread;
         public static final int MAX_PRIORITY = 10;
         Vector lines = new Vector();
         Color jfcBlue = new Color(204, 204, 255);
    Color pink = new Color(255, 175, 175);
    private Font font12 = new Font("serif", Font.PLAIN, 12);
    long mainSize = 36000;
    int holdingArray[];
    int ZOOMFactor;
         private JPanel jContentPane = null;
         * This is the default constructor
         public DisWav1() {
              super();
              initialize();
         * This method initializes this
         * @return void
         private void initialize() {
              this.setBackground(java.awt.Color.black);
              this.setContentPane(getJContentPane());
              this.setTitle("Display Wave");
    this.setSize(150,150);
    addMouseWheelListener(new java.awt.event.MouseWheelListener() {
    public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
    formMouseWheelMoved(evt);
         * This method initializes jContentPane
         * @return javax.swing.JPanel
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new JPanel();
                   jContentPane.setBackground(java.awt.Color.black);
                   jContentPane.setLayout(new BorderLayout());
              return jContentPane;
         public void run()
    }// end run
    public void start() {
    thread = new Thread(this);
    thread.setName("Display Graph");
    thread.setPriority(MAX_PRIORITY );
    thread.start();
    }// end start
    public void stop() {
    if (thread != null) {
    thread.interrupt();
    thread = null;
    }// end stop
    // Create a array for drawing ines on screen in scale.
    public void moveMe(int x, int y){
    this.setLocation(x,y);
    // used to detect when the mouse is wheel is move and then
    // zoom IN or OUT
    // also display jLabel with animated gif saying "zooming in" or "Zooming out"
    private void formMouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
    javax.swing.JLabel zz;
    zz = new javax.swing.JLabel();
    zz.setBounds(this.getWidth()/2, this.getHeight()/2, 140,40);
    zz.setText("");
    getContentPane().add(zz);
    int notches = evt.getWheelRotation();
    if (notches < 0) {
    getContentPane().add(zz);
    zz.setIcon(new javax.swing.ImageIcon("zoomingin.gif"));
    zz.setBounds(this.getWidth()/2-(zz.getWidth()/2), this.getHeight()/2-(zz.getHeight()/2), 140,40);
    System.out.println("zoom up " + ZOOMFactor);
    ZOOMFactor = ZOOMFactor +2;
    } else {
    if (ZOOMFactor <= 0 )
         ZOOMFactor = 1;
    else{
    getContentPane().add(zz);
    zz.setIcon(new javax.swing.ImageIcon("C:zoomingOUT.gif"));
    zz.setBounds(this.getWidth()/2-(zz.getWidth()/2), this.getHeight()/2-(zz.getHeight()/2), 140,40);
    ZOOMFactor = ZOOMFactor - 2;
    System.out.println("zoom down " + ZOOMFactor);
    public void paint(Graphics g) {
    // paints lines form a vector here on the screen
    }// end of paint method
    }// end class disWav1
    // END CODE

    think ive solved it

Maybe you are looking for