本文介绍了Java BasicStroke“模糊"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 Java 编写一个简单的绘图小程序,但是我在使用 BasicStroke 时遇到了问题.最初,我的计划是尝试以某种方式绘制一条具有宽度的线,但 API 显然不支持.

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.

我尝试使用 BasicStroke,但结果只是一团糟.我该如何解决这个模糊问题?

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

推荐答案

不要忘记 渲染提示:

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

这篇关于Java BasicStroke“模糊"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-05 13:20