How to leave the line border drawn with Graphics in Java straight?

3

I made a program that draws lines on the screen, but the line gets very deformed (image 2) on certain links. I would like to know if there is a way to make the edge of the line straight (image 1), whatever the tilt of it.

I'm using Graphics2D .

    
asked by anonymous 29.03.2018 / 18:39

1 answer

2
___ erkimt ___ How to leave the line border drawn with Graphics in Java straight? ______ qstntxt ___

I made a program that draws lines on the screen, but the line gets very deformed (image 2) on certain links. I would like to know if there is a way to make the edge of the line straight (image 1), whatever the tilt of it.

I'm using RenderingHints .

    
_________azszpr287550

Use the import static java.awt.RenderingHints.* :

private static final RenderingHints HINTS = new RenderingHints(null);
static {
    HINTS.put(KEY_ALPHA_INTERPOLATION, VALUE_ALPHA_INTERPOLATION_QUALITY);
    HINTS.put(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON); 
    HINTS.put(KEY_COLOR_RENDERING, VALUE_COLOR_RENDER_QUALITY); 
    HINTS.put(KEY_INTERPOLATION, VALUE_INTERPOLATION_BICUBIC); 
    HINTS.put(KEY_STROKE_CONTROL, VALUE_STROKE_NORMALIZE);
}

@Override
public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHints(HINTS);

    // Prossiga com seu desenho aqui.
}

All these keys and values are added with KEY_ANTIALIASING . The most important is the VALUE_ANTIALIAS_ON % and% %code% that activates the anti-aliasing.

For more details, see the TCC I made in this area in 2007 .

    
___
29.03.2018 / 18:54