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

问题描述

我试图写一个简单的小程序漆使用Java,但我在使用的BasicStroke 麻烦。最初,我的计划是试图以某种方式绘制宽度的线,但显然API不支持。

我试着用的BasicStroke ,但结果只是一个模糊的一塌糊涂。我怎样才能解决这个问题细毛?

 私人无效mousedrag_hook(点对点)
    {
        如果(开始== NULL)
            开始=点;            结束=点;            Graphics2D的G2D =(Graphics2D的)applInstance.buffer_g;
            g2d.setStroke(新的BasicStroke(7));            //g2d.fillOval(point.x - 5,point.y - 5,10,10);
            g2d.drawLine(start.x,start.y,end.x,end.y);
            applInstance.repaint();            开始=结束;
    }


解决方案

不要忘了的:

  @覆盖
公共无效的paintComponent(图形G){
    super.paintComponent方法(G);
    Graphics2D的G2D =(Graphics2D的)克;
    g2d.setRenderingHint(
        RenderingHints.KEY_ANTIALIASING,
        RenderingHints.VALUE_ANTIALIAS_ON);
    ...
}

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;
    }
解决方案

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

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

08-23 11:52