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

MultiResolution image: what is an expected behavior when one of the image files (@1x or @2x) is invalid/empty?

      Please save attached image.png, image@2x.png to some folder and compile/run the following test code (in HiDPI mode):

      import java.awt.*;
      import java.awt.event.*;
      import java.io.File;

      public class Test extends Frame {

          static Image img;
          public Test() { EventQueue.invokeLater(this::CreateUI); }

          private void CreateUI() {
              addWindowListener(new WindowAdapter() {
                  @Override
                  public void windowClosing(WindowEvent e) { dispose(); }
              });

              setSize(200, 200);
              setVisible(true);
          }

          @Override
          public void paint(Graphics gr) {
              Graphics2D g = (Graphics2D) gr;
              if (g != null) {
                  File imageFile = new File("image.png");
                  String fileName = imageFile.getAbsolutePath();
                  img = Toolkit.getDefaultToolkit().getImage(fileName);
                  g.drawImage(img, 50, 50, this);
              }
          }

          public static void main(String[] args) throws Exception { new Test(); }
      }

      expected behavior - the blue square is drawn.

      then corrupt @2x image:
      > echo "?!?" > image@2x.png
      or
      > rm image@2x.png
      > touch image@2x.png
      and run again - the green square is drawn (this looks reasonable: cannot load @2x image => load @1x image).

      please restore image@2x.png and corrupt image.png:
      > echo "?!?" > image.png
      and run again: image@2x is not loaded. Shouldn't we try to load the uncorrupted image@2x.png? So there is some asymmetry here.

      Checked with: Mac OS X 10.10 + Quartz, JDK9 b77

        1. image.png
          image.png
          0.2 kB
        2. image@2x.png
          image@2x.png
          0.4 kB

          Loading...
          Uploaded image for project: 'JDK'
          1. JDK
          2. JDK-8142405

          MultiResolution image: what is an expected behavior when one of the image files (@1x or @2x) is invalid/empty?

              Please save attached image.png, image@2x.png to some folder and compile/run the following test code (in HiDPI mode):

              import java.awt.*;
              import java.awt.event.*;
              import java.io.File;

              public class Test extends Frame {

                  static Image img;
                  public Test() { EventQueue.invokeLater(this::CreateUI); }

                  private void CreateUI() {
                      addWindowListener(new WindowAdapter() {
                          @Override
                          public void windowClosing(WindowEvent e) { dispose(); }
                      });

                      setSize(200, 200);
                      setVisible(true);
                  }

                  @Override
                  public void paint(Graphics gr) {
                      Graphics2D g = (Graphics2D) gr;
                      if (g != null) {
                          File imageFile = new File("image.png");
                          String fileName = imageFile.getAbsolutePath();
                          img = Toolkit.getDefaultToolkit().getImage(fileName);
                          g.drawImage(img, 50, 50, this);
                      }
                  }

                  public static void main(String[] args) throws Exception { new Test(); }
              }

              expected behavior - the blue square is drawn.

              then corrupt @2x image:
              > echo "?!?" > image@2x.png
              or
              > rm image@2x.png
              > touch image@2x.png
              and run again - the green square is drawn (this looks reasonable: cannot load @2x image => load @1x image).

              please restore image@2x.png and corrupt image.png:
              > echo "?!?" > image.png
              and run again: image@2x is not loaded. Shouldn't we try to load the uncorrupted image@2x.png? So there is some asymmetry here.

              Checked with: Mac OS X 10.10 + Quartz, JDK9 b77

                1. image.png
                  image.png
                  0.2 kB
                2. image@2x.png
                  image@2x.png
                  0.4 kB

                    alexsch Alexandr Scherbatiy
                    avstepan Alexander Stepanov (Inactive)
                    Votes:
                    0 Vote for this issue
                    Watchers:
                    2 Start watching this issue

                      Created:
                      Updated:
                      Resolved:

                        alexsch Alexandr Scherbatiy
                        avstepan Alexander Stepanov (Inactive)
                        Votes:
                        0 Vote for this issue
                        Watchers:
                        2 Start watching this issue

                          Created:
                          Updated:
                          Resolved: