Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4253075

Animated GIFs with transparent backgrounds do not work when scaled

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.3.0
    • 1.1.7, 1.2.2, 1.3.0
    • client-libs
    • kestrel
    • generic, sparc
    • generic, solaris_2.6



      Name: rlT66838 Date: 07/09/99


      Animated GIFs with transparent backgrounds do not render correctly if the image is scaled. Non-animated GIFs and animated GIFs with non-transparent backgrounds can be scaled and rendered properly. Animated GIFs with transparent backgrounds are rendered properly only if they are not scaled.

      This example was tested with JDK 1.1.8 with Swing 1.1.1-beta2 on Windows NT4(SP4) as well as 1.2.2

      ================

      import java.awt.*;
      import java.awt.event.*;
      import java.net.*;
      import javax.swing.*;
      import javax.swing.event.*;

      public class animtest extends JFrame
      {
          public animtest()
          {
              addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  }
              });
              
              ImageIcon transparent = null;
              ImageIcon nontransparent = null;
              try {
                  nontransparent = new ImageIcon(new URL("http://java.sun.com/products/jfc/tsc/page_1_art/Swing-64.gif"));
                  transparent = new ImageIcon(new URL("http://www.thejavahut.com/gmove.gif"));
              }
              catch (Exception e) {}

              // the images render correctly if
              // the code below is commented out
              /**/
              // scale images to double size
              Image img = nontransparent.getImage();
              img = img.getScaledInstance(2*img.getWidth(null),
                    2*img.getHeight(null), Image.SCALE_DEFAULT);
              nontransparent = new ImageIcon(img);
              img.flush();
              Image img2 = transparent.getImage();
              img2 = img2.getScaledInstance(2*img.getWidth(null),
                     2*img.getHeight(null), Image.SCALE_DEFAULT);
              transparent = new ImageIcon(img2);
              img2.flush();
              /**/
              
              getContentPane().setLayout(new GridLayout(1,2));
              getContentPane().add(new JLabel(nontransparent));
              getContentPane().add(new JLabel(transparent));
              pack();
              show();
          }

          public static void main(String[] args)
          {
              new animtest();
          }
      }
      (Review ID: 85430)
      ======================================================================

            jeff Jeff Dinkins
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: