Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
512 views
in Technique[技术] by (71.8m points)

graphics - Java BasicStroke "Fuzzy"

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?

typical result

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;
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);
    ...
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...