Java BasicStroke “Fuzzy”

被刻印的时光 ゝ 提交于 2019-12-17 22:01:35

问题


I'm trying to write a simple paint applet with Java, but I'm having trouble with BasicStroke. Initially, my plan was to try to somehow draw a line with a width, but the API apparently doesn't support that.

I tried using BasicStroke, but the result is just a fuzzy mess. How can I fix this fuzz problem?

private void mousedrag_hook(Point point)
    {
        if(start == null)
            start = point;

            end = point;

            Graphics2D g2d = (Graphics2D)applInstance.buffer_g;
            g2d.setStroke(new BasicStroke(7));

            //g2d.fillOval(point.x - 5, point.y - 5, 10, 10);
            g2d.drawLine(start.x, start.y, end.x, end.y);
            applInstance.repaint();

            start = end;
    }

回答1:


Don't forget the RenderingHints:

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(
        RenderingHints.KEY_ANTIALIASING,
        RenderingHints.VALUE_ANTIALIAS_ON);
    ...
}


来源:https://stackoverflow.com/questions/6991648/java-basicstroke-fuzzy

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