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

Big images are not rendered in Java Swing on JPanel

XMLWordPrintable

    • 2d
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Ubuntu 18.04 / 20.04
      OpenSuse 11.3

      A DESCRIPTION OF THE PROBLEM :
      if image has a size bigger than 32768 in on axis it not displayed when doing a drawImage on JPanel

      also if image is smaller and affinetransformation is used as soon as the values of the transformation increase.
      I noted if I translated more then 32768 pixel the image is not shown7rendered anymore.

      There is no exception!


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      create a JP which is colored and 40000pxx2000px
      load it into a BufferedImage
      add a Jpanel to the Frame
      drawImage(img,0,0,null)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      visible part image is shown on the Jpanel
      when doing an affine tranformation and the image size is increased by scaling at certain degree the image disappears from the panel

      For me it looks like as soon as some values (translation) become > 32768 the image disappears

      The transformationmatrix is define as double but it looks like as in the background some values are handles like float
      ACTUAL -
      Image is not displayed or disappears when zooming

      ---------- BEGIN SOURCE ----------


      import java.awt.BorderLayout;
      import java.awt.Dimension;
      import javax.swing.JFrame;
      import javax.swing.SwingUtilities;

      public class ImageZoomer {
          public static boolean DEBUG = false;
         
          final static String filename = "Pano2.jpg";

          public static void main(String[] args) throws InterruptedException {
              showMemory();
              SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      final JFrame frame = new JFrame("PicturePanel");
                      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      PicturePanel ucpanel = new PicturePanel(filename, 425);
                      frame.getContentPane().add(ucpanel, BorderLayout.CENTER);
                      frame.setSize(new Dimension(1920, 600));
                      frame.setVisible(true);
                  }
              });
              Thread.sleep(2000);
              showMemory();
          }

          public static void showMemory() {
              Runtime rt = Runtime.getRuntime();
              long totalMem = rt.totalMemory();
              long maxMem = rt.maxMemory();
              long freeMem = rt.freeMemory();
              double megs = 1048576.0;
              System.out.println("------------------------------------------------");
              System.out.println("Total Memory: " + totalMem + " (" + (totalMem / megs) + " MiB)");
              System.out.println("Max Memory: " + maxMem + " (" + (maxMem / megs) + " MiB)");
              System.out.println("Free Memory: " + freeMem + " (" + (freeMem / megs) + " MiB)");
          }
      }





      import java.awt.Dimension;
      import java.awt.geom.AffineTransform;
      import java.awt.image.BufferedImage;

      public class TransformParam {
          double translateX = 0;
          double translateY = 0;
          double scaleX = 1;
          double scaleY = 1;
          double stretchX = 1;
          double prescaler = 1;

          public void fitInRangeTranslateX(double min, double max) {
              if (translateX < min)
                  translateX = min;
              else if (translateX > max)
                  translateX = max;
          }

          public void fitInRangeTranslateY(double min, double max) {
              if (translateY < min)
                  translateY = min;
              else if (translateY > max)
                  translateY = max;
          }

          public AffineTransform getAffineTransFormParam(BufferedImage image, Dimension dim) {
              AffineTransform at = new AffineTransform();
              double t1x = -(double) image.getWidth(null) / 2 * scaleX * prescaler;
              double t1y = -(double) image.getHeight(null) / 2 * scaleY * prescaler;
              double sx = scaleX * prescaler;
              double sy = scaleY * prescaler;
              double t2x = (double) dim.width / 2 / scaleX / prescaler;
              double t2y = (double) dim.height / 2 / scaleY / prescaler;

              if (ImageZoomer.DEBUG)
                  System.out.println("T1X: " + t1x + "\tT1Y: " + t1y + "\tSX: " + sx + "\tSY: " + sy + "\tT2X: " + t2x
                          + "\tT2Y: " + t2y);

              // // the prescale, stretch_x and zoom transformation
              at.setToIdentity();
              at.translate(t1x, t1y);
              at.scale(sx, sy);
              at.translate(t2x, t2y);
              // The panning transformation
              at.translate(translateX, translateY);
              return at;
          }

          public void reset() {
              translateX = translateY = 0;
              scaleX = scaleY = stretchX = prescaler = 1;
          }

          @Override
          public String toString() {
              return "translateX: " + translateX + "\ttranslateY: " + translateY + "\tstretchX: " + stretchX + "\tscaleX: "
                      + scaleX + "\tscaleY: " + scaleY + "\tprescaler: " + prescaler;
          }
      }




      import java.awt.Dimension;
      import java.awt.geom.AffineTransform;
      import java.awt.image.BufferedImage;

      public class TransformParam {
          double translateX = 0;
          double translateY = 0;
          double scaleX = 1;
          double scaleY = 1;
          double stretchX = 1;
          double prescaler = 1;

          public void fitInRangeTranslateX(double min, double max) {
              if (translateX < min)
                  translateX = min;
              else if (translateX > max)
                  translateX = max;
          }

          public void fitInRangeTranslateY(double min, double max) {
              if (translateY < min)
                  translateY = min;
              else if (translateY > max)
                  translateY = max;
          }

          public AffineTransform getAffineTransFormParam(BufferedImage image, Dimension dim) {
              AffineTransform at = new AffineTransform();
              double t1x = -(double) image.getWidth(null) / 2 * scaleX * prescaler;
              double t1y = -(double) image.getHeight(null) / 2 * scaleY * prescaler;
              double sx = scaleX * prescaler;
              double sy = scaleY * prescaler;
              double t2x = (double) dim.width / 2 / scaleX / prescaler;
              double t2y = (double) dim.height / 2 / scaleY / prescaler;

              if (ImageZoomer.DEBUG)
                  System.out.println("T1X: " + t1x + "\tT1Y: " + t1y + "\tSX: " + sx + "\tSY: " + sy + "\tT2X: " + t2x
                          + "\tT2Y: " + t2y);

              // // the prescale, stretch_x and zoom transformation
              at.setToIdentity();
              at.translate(t1x, t1y);
              at.scale(sx, sy);
              at.translate(t2x, t2y);
              // The panning transformation
              at.translate(translateX, translateY);
              return at;
          }

          public void reset() {
              translateX = translateY = 0;
              scaleX = scaleY = stretchX = prescaler = 1;
          }

          @Override
          public String toString() {
              return "translateX: " + translateX + "\ttranslateY: " + translateY + "\tstretchX: " + stretchX + "\tscaleX: "
                      + scaleX + "\tscaleY: " + scaleY + "\tprescaler: " + prescaler;
          }
      }


      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      use an old java 7 runtime

      FREQUENCY : always


        1. biggreen.jpg
          biggreen.jpg
          57 kB
        2. Capture.PNG
          Capture.PNG
          12 kB
        3. TestApp.java
          3 kB

            pnarayanaswa Praveen Narayanaswamy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: