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

[hidpi] multi-res. image: the base image is used for filtering regardless of the scale?

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • 9
    • 9
    • client-libs

      Please compile/run the following code:

      import java.awt.*;
      import java.awt.image.*;
      import javax.swing.*;

      public class MenuIconTest extends JFrame {

          private final static int SZ = 32;

          private final static Color C1X = Color.RED, C2X = Color.BLUE;

          private static BufferedImage generateImage(int scale, Color c) {
              int x = SZ * scale;
              BufferedImage img = new BufferedImage(x, x, BufferedImage.TYPE_INT_RGB);
              Graphics g = img.getGraphics();
              g.setColor(c);
              g.fillRect(0, 0, x, x);
              g.setColor(Color.WHITE);
              g.fillRect(x / 3, x / 3, x / 3, x / 3);
              return img;
          }
          
          public MenuIconTest() throws Exception { SwingUtilities.invokeAndWait(this::UI); }

          private void UI() {
              
              BaseMultiResolutionImage mri = new BaseMultiResolutionImage(
                  new BufferedImage[] {generateImage(1, C1X), generateImage(2, C2X)});
              ImageIcon icon = new ImageIcon(mri);
              
              Toolkit tk = Toolkit.getDefaultToolkit();
              // in fact, the filter does nothing
              CropImageFilter filter = new CropImageFilter(0, 0, SZ, SZ);
              ImageIcon iconFiltered = new ImageIcon(tk.createImage(
                      new FilteredImageSource(mri.getSource(), filter)));
              
              JMenuBar menuBar = new JMenuBar();
              JMenu menu = new JMenu("menu");
              menuBar.add(menu);
              menu.add(new JMenuItem("item 1", icon));
              menu.add(new JMenuItem("item 2", iconFiltered));

              setJMenuBar(menuBar);
              
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              setSize(200, 100);
              setVisible(true);
          }

          public static void main(String s[]) throws Exception {
              
              System.setProperty("sun.java2d.uiScale", "2");
              new MenuIconTest();
          }
      }


      please open the menu. the 2x "blue" image is used for item 1.

      note that sizes of icons for "item 1" and "item 2" are equal - that's what expected.

      but the icon color for "item 2" is red. So there is seemingly some inconsistency here (the 1st naive expectation was that the "blue" image variant of the initial multires. image should be filtered).

      Win. 7 + JDK9 b106


      and just a question: does there exist a way to filter all the resolution variants for the multires. image at once?
      because the following consecution gives a multires. image with a single resolution variant:

          BaseMultiResolutionImage mriFiltered = new BaseMultiResolutionImage(tk.createImage(
                      new FilteredImageSource(mri.getSource(), filter)));

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

              Created:
              Updated:
              Resolved: