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

[macosx] Multi resolution image: should it be possible to load tiff?



    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Won't Fix
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: client-libs
    • Labels:


      Not sure if a bug, just in case:

      was checked with Quartz Debug emulation for HiDPI.

      please run the following code:

      import java.awt.*;
      import java.awt.event.*;
      import java.awt.image.*;
      import java.io.File;
      import javax.imageio.ImageIO;

      public class Test extends Frame {

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

          private static final int sz = 100;
          private static final String name1x = "image.png";
          private static final String name2x = "image@2x.png";

          static void generateImages() throws Exception {
              if (!new File(name1x).exists()) { generateImage(1); }
              if (!new File(name2x).exists()) { generateImage(2); }

          static void generateImage(int scale) throws Exception {
              BufferedImage image = new BufferedImage(scale * sz, scale * sz, BufferedImage.TYPE_INT_RGB);
              Graphics g = image.getGraphics();
              g.setColor(scale == 1 ? Color.GREEN : Color.BLUE);
              g.fillRect(0, 0, scale * sz, scale * sz);
              File file = new File(scale == 1 ? name1x : name2x);
              ImageIO.write(image, "png", file);

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

              setSize(300, 300);

          public void paint(Graphics gr) {
              Graphics2D g = (Graphics2D) gr;
              if (g != null) {
                  File imageFile = new File(name1x);
                  //File imageFile = new File("image.tiff");
                  String fileName = imageFile.getAbsolutePath();
                  img = Toolkit.getDefaultToolkit().getImage(fileName);
                  g.drawImage(img, 0, 0, this);

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

      The behavior is as expected (blue square for HiDPI, green - for the default display resolution).

      Then please merge "image.png" + "image@2x.png" pair using tiffutil and then remove png-files:
      tiffutil -cathidpicheck image.png image@2x.png -out image.tiff
      rm *.png

      Please return to the test code and replace
      "File imageFile = new File(name1x);"
      "File imageFile = new File("image.tiff");"
      and comment out generateImages call in main. No image is drawn when running (as Toolkit.getImage() does not support TIFF for now). JDK9 b77 is used; OS: Mac OS X 10.10.3

      The tiff image is correct and contains two images (checked using macosx Preview).

      The following cocoa code displays the tiff file correctly (blue/green square, depending on is HiDPI emulation id on or off):

      echo '#import <Cocoa/Cocoa.h>
      int main() {
          [NSAutoreleasePool new];
          [NSApplication sharedApplication];
          [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
          id appName = [[NSProcessInfo processInfo] processName];

          id img = [NSImage imageNamed:@"image.tiff"];

          NSRect frame = NSMakeRect(0, 0, 400, 400);
          NSUInteger styleMask = NSTitledWindowMask;
          NSRect rect = [NSWindow contentRectForFrameRect:frame styleMask:styleMask];
          id window = [[NSWindow alloc] initWithContentRect:rect styleMask:styleMask backing:NSBackingStoreBuffered defer:false];

          id imView = [[NSImageView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)];
          [imView setImage:img];
          [imView setImageScaling:NSImageScaleProportionallyDown];

          [window setContentView:imView];
          [window makeKeyAndOrderFront:nil];
          [window cascadeTopLeftFromPoint:NSMakePoint(20, 20)];
          [window setTitle:appName];
          [NSApp activateIgnoringOtherApps:YES];
          [NSApp run];
          return 0;
      }' | gcc -framework Cocoa -x objective-c -o runTest - ; ./runTest


          Issue Links



              bpb Brian Burkhalter
              avstepan Alexander Stepanov
              0 Vote for this issue
              4 Start watching this issue