Java Swing, all images appear pixelated

微笑、不失礼 提交于 2021-02-20 04:23:25

问题


Every image in my Java Swing Programs will appear in low quality as shown below:

As you can see from the image, it is not just images I am having problem with, it's graphics in general displaying like this. In the right portion you can see the problem reflected to a JFreeChart Graphic. Has anyone else had this problem, is it related to the graphics card or maybe windows DPI? The same programs will render perfectly fine in other machines so I am pretty sure it is not related to the code.


回答1:


If you are using g2d, try enabling antialiasing.

g2d.setRenderingHint(
    RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);

(more info: Java2D Graphics anti-aliased)

In JFreeChart try the following code:

chart.setRenderingHints(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON));

(source: http://www.jfree.org/forum/viewtopic.php?t=7958)




回答2:


The problem in my case was that I had scaling turned on at 125% on Windows and images and frames had to be zoomed in order to fit the size they were given. All you have to do is go to Display Settings and at section Scale and layout set zoom to 100%.

If you don't fancy turning down scaling you could add this parameter to the VM on your IDE by adding this parameter:

-Dsun.java2d.dpiaware=false

Alternatively, try this if the first one doesn't work.

-Dsun.java2d.uiScale=1.0

This only works for Swing



来源:https://stackoverflow.com/questions/50455176/java-swing-all-images-appear-pixelated

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!