【发布时间】:2022-01-18 18:24:43
【问题描述】:
我已经从http://people.apache.org/~clay/batik/svgcanvas.html 复制粘贴了很多代码 但输出的 svg 是模糊的。我同时使用了 fontawesome 和材质 ui svg,但两者都很模糊。我究竟做错了什么?这是我的代码:
public class GUI extends JFrame{
public void init(){
initFrame();
CardLayout cl = new CardLayout();
JPanel panel = new JPanel(cl);
panel.add(createHome(), "HOME");
panel.setBackground(new Color(200, 0, 50));
cl.show(panel, "HOME");
add(panel);
setSize(1280, 720);
setVisible(true);
}
private JPanel createHome(){
JPanel p = new JPanel(new BorderLayout());
{
JPanel d = new JPanel(new FlowLayout(FlowLayout.LEFT));
d.setBackground(new Color(0, 0, 0, 0));
p.add(d, BorderLayout.PAGE_START);
JSVGCanvas svg = new JSVGCanvas();
d.setSize(this.getWidth(), 50);
d.add(svg);
String s = new File("images/userIcon3.svg").toURI().toString();
svg.setMySize(new Dimension(200, 200));
svg.setURI(s);
}
p.setBackground(new Color(0, 50, 200));
p.setSize(this.getWidth(), this.getHeight());
return p;
}
private void initFrame(){
int width = 1280, height = 720;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int swidth = screenSize.width, sheight = screenSize.height;
setTitle("Travelling Agency");
setLocation((swidth - width) / 2, (sheight - height) / 2); //Position it in the center
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
}
【问题讨论】:
-
你需要开启抗锯齿
-
System.setProperty("awt.useSystemAAFontSettings","on"); System.setProperty("swing.aatext", "true");在main方法中
-
对我没用...@JustanotherJavaprogrammer
-
@JustanotherJavaprogrammer 实际上做到了!