在Java应用程序端控制图像质量

在Java应用程序端控制图像质量,java,windows-10,scaling,dpi,Java,Windows 10,Scaling,Dpi,我发布了一个问题,询问如何处理java应用程序中的模糊图片。我发现我的视窗缩放造成了模糊。现在我有一个更大的问题。我希望通过应用程序控制图像和应用程序的质量,如果可能的话,不必更改任何windows设置 不是将缩放比例改回100%,而是另一个windows建议,即更改java.exe和/或javaw.exe的兼容性设置,以覆盖高DPI设置,由系统执行缩放。它是有效的,因为画面更清晰,但文字却失去了清晰 我发现应用程序的最佳质量是不覆盖高DPI,而只是将缩放设置为100%。文字清晰,图片也清晰 我

我发布了一个问题,询问如何处理java应用程序中的模糊图片。我发现我的视窗缩放造成了模糊。现在我有一个更大的问题。我希望通过应用程序控制图像和应用程序的质量,如果可能的话,不必更改任何windows设置

不是将缩放比例改回100%,而是另一个windows建议,即更改java.exe和/或javaw.exe的兼容性设置,以覆盖高DPI设置,由系统执行缩放。它是有效的,因为画面更清晰,但文字却失去了清晰

我发现应用程序的最佳质量是不覆盖高DPI,而只是将缩放设置为100%。文字清晰,图片也清晰

我正在试图找出是否有一种方法可以保持这种质量,而不必让用户更改任何windows设置以使应用程序看起来良好。我想知道代码中是否有实现这一点的方法

下面是一个示例程序,我的缩放比例为125%。图片模糊,但文字良好。

下面是一个DPI被系统覆盖的示例,缩放比例仍为125%,注意文本失去了清晰性,但图片更好

最后,缩放为100%,不再覆盖DPI。这是最好的文字和图片质量

如果有人需要,下面是示例代码

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Color;
import java.awt.Component;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import java.awt.Insets;
import java.awt.Font;
import java.awt.Dimension;
import javax.swing.JTextArea;

@SuppressWarnings("serial")
public class example extends JFrame {

private JPanel contentPane;

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                example frame = new example();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

public example() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 558, 373);
    contentPane = new JPanel();
    contentPane.setBackground(Color.WHITE);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    GridBagLayout gbl_contentPane = new GridBagLayout();
    gbl_contentPane.columnWidths = new int[]{0, 0};
    gbl_contentPane.rowHeights = new int[]{0, 0};
    gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE};
    gbl_contentPane.rowWeights = new double[]{1.0, Double.MIN_VALUE};
    contentPane.setLayout(gbl_contentPane);

    JPanel panel = new JPanel();
    panel.setBackground(Color.WHITE);
    GridBagConstraints gbc_panel = new GridBagConstraints();
    gbc_panel.fill = GridBagConstraints.BOTH;
    gbc_panel.gridx = 0;
    gbc_panel.gridy = 0;
    contentPane.add(panel, gbc_panel);
    GridBagLayout gbl_panel = new GridBagLayout();
    gbl_panel.columnWidths = new int[]{0, 0, 0};
    gbl_panel.rowHeights = new int[]{0, 0, 0, 100, 0};
    gbl_panel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
    gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
    panel.setLayout(gbl_panel);

    JLabel lblWordsGoHere = new JLabel("Words go here");
    lblWordsGoHere.setFont(new Font("Cambria Math", Font.PLAIN, 18));
    GridBagConstraints gbc_lblWordsGoHere = new GridBagConstraints();
    gbc_lblWordsGoHere.insets = new Insets(0, 0, 5, 0);
    gbc_lblWordsGoHere.gridx = 1;
    gbc_lblWordsGoHere.gridy = 0;
    panel.add(lblWordsGoHere, gbc_lblWordsGoHere);

    Component horizontalStrut = Box.createHorizontalStrut(20);
    horizontalStrut.setPreferredSize(new Dimension(20, 20));
    GridBagConstraints gbc_horizontalStrut = new GridBagConstraints();
    gbc_horizontalStrut.insets = new Insets(0, 0, 5, 5);
    gbc_horizontalStrut.gridx = 0;
    gbc_horizontalStrut.gridy = 1;
    panel.add(horizontalStrut, gbc_horizontalStrut);

    JLabel lblNewLabel = new JLabel("More words here...");
    lblNewLabel.setFont(new Font("Cambria Math", Font.PLAIN, 14));
    GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
    gbc_lblNewLabel.insets = new Insets(0, 0, 5, 0);
    gbc_lblNewLabel.anchor = GridBagConstraints.WEST;
    gbc_lblNewLabel.gridx = 1;
    gbc_lblNewLabel.gridy = 1;
    panel.add(lblNewLabel, gbc_lblNewLabel);

    JLabel lblNewLabel_1 = new JLabel(new ImageIcon(example.class.getResource("/icons/Step3.png")));
    GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
    gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 0);
    gbc_lblNewLabel_1.gridx = 1;
    gbc_lblNewLabel_1.gridy = 2;
    panel.add(lblNewLabel_1, gbc_lblNewLabel_1);

    JTextArea txtrLotsOfDescriptive = new JTextArea();
    txtrLotsOfDescriptive.setLineWrap(true);
    txtrLotsOfDescriptive.setWrapStyleWord(true);
    txtrLotsOfDescriptive.setEditable(false);
    txtrLotsOfDescriptive.setFont(new Font("Cambria Math", Font.PLAIN, 14));
    txtrLotsOfDescriptive.setText("Lorem ipsum dolor sit amet, eu tempor maluisset eum. Ipsum detracto mediocrem quo eu. Eos ad ocurreret argumentum. Cum ei vero ipsum alienum, has sonet impetus repudiandae at, cu viris assentior eum.");
    GridBagConstraints gbc_txtrLotsOfDescriptive = new GridBagConstraints();
    gbc_txtrLotsOfDescriptive.fill = GridBagConstraints.BOTH;
    gbc_txtrLotsOfDescriptive.gridx = 1;
    gbc_txtrLotsOfDescriptive.gridy = 3;
    panel.add(txtrLotsOfDescriptive, gbc_txtrLotsOfDescriptive);
}
}