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

ImageReader produces incorrect size of image for further frames of animated GIF

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      I was using OpenJDK 16.0.2, but I had also tried to run my program on JRE 8 and it seems to be old problem with
      every Java version.

      A DESCRIPTION OF THE PROBLEM :
      When I try to read animated gif frame by frame, only a first frame has desired size and the rest of frames seems to be cropped by lines with all transparent pixels.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      try the following code:

              int frames_count;
              ArrayList<BufferedImage> anim;
              BufferedImage img;
              
              ImageReader img_reader;
              ImageInputStream img_stream;
              
              img_reader = ImageIO.getImageReadersByMIMEType("image/gif").next();
              img_stream = ImageIO.createImageInputStream(new File("animated-gif-file.gif"));
              img_reader.setInput(img_stream);
              
              frames_count = img_reader.getNumImages(true);
              anim = new ArrayList<BufferedImage>();
              for (int i=0;i<frames_count;i++) {
                  img = img_reader.read(i);
                  System.out.println("Frame "+i+" width: "+img.getWidth());
                  anim.add(img);
              }
            

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I was expecting to every gif frame (img) has the same size of 32x32 pixels.
      ACTUAL -
      for my 32x32 gif image (with two frames of animation) it will print in command line:
      Frame 0 width: 32
      Frame 1 width: 18

      Like I have written further frames are cropped by transparent pixels.


      FREQUENCY : always


            jdv Jayathirth D V
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: