Drawing HiDPI component to BufferedImage

Sergey Bylokhov Sergey.Bylokhov at oracle.com
Fri Jan 24 06:35:42 PST 2014


On 24.01.2014 18:20, Hendrik Schreiber wrote:
> However, your other suggestion (double size bufferedimage), does not work. Is this intended or a bug?
What happen if you change l&f to the Nimbus?  I suggest to file the new 
CR to investigate this.
>
> Thanks!
>
> -hendrik
>
>
>
> Here's a simple demo class. I'd expect both checkboxes to render in the same quality, but they don't using a BufferedImage.
>
> import javax.swing.*;
> import java.awt.*;
> import java.awt.image.BufferedImage;
>
> public class RenderHiDPI {
>
>      public static void main(String[] args) {
>          final JFrame frame = new JFrame();
>          final JLabel label = new JLabel();
>          frame.getContentPane().setLayout(new FlowLayout());
>          final JCheckBox hiDPICheckBox = new JCheckBox("Hi DPI");
>          hiDPICheckBox.setFocusable(false);
>          frame.getContentPane().add(hiDPICheckBox);
>          frame.getContentPane().add(label);
>          final JCheckBox checkBox = new JCheckBox("Lo DPI");
>          checkBox.setSize(new Dimension(100, 100));
>          final BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);
>          final Graphics g = image.getGraphics();
>          ((Graphics2D)g).scale(2f, 2f);
>          checkBox.paint(g);
>          g.dispose();
>          label.setIcon(new Icon(){
>              @Override
>              public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
>                  final Graphics2D graphics = (Graphics2D)g.create();
>                  graphics.scale(0.5f, 0.5f);
>                  graphics.drawImage(image, x, y, c);
>              }
>
>              @Override
>              public int getIconWidth() {
>                  return 100;
>              }
>
>              @Override
>              public int getIconHeight() {
>                  return 100;
>              }
>          });
>
>          SwingUtilities.invokeLater(new Runnable() {
>              @Override
>              public void run() {
>                  frame.setBounds(100, 100, 100, 100);
>                  frame.setVisible(true);
>              }
>          });
>      }
> }


-- 
Best regards, Sergey.



More information about the macosx-port-dev mailing list