我正在尝试用Java编写一个简单的绘图小程序,但我遇到了BasicStroke
的问题。最初,我的计划是尝试以某种方式绘制一个宽度的线,但API显然不支持。
我尝试使用BasicStroke
,但结果只是一个模糊的混乱。如何修复此模糊问题?
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;
}
答案 0 :(得分:5)
不要忘记RenderingHints
:
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
...
}