Drawing circles with smoother lines?
hiya,
just like to get some information on drawing circles.
the output from the code below displays a circle but the lines are broken.
thanks
Code :
import java.awt.*;
import javax.swing.*;
import java.applet.*;
public class Circles extends JApplet
{
public void init()
{
}
public void paint(Graphics g)
{
g.drawOval(10, 10, 100, 100);
}
}
Re: Drawing circles with smoother lines?
-- Cast the Graphics to Graphics2D :
Code :
Graphics2D g2 = (Graphics2D) g;
-- set the rendering hint:
Code :
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
db
Re: Drawing circles with smoother lines?
At a certain point, there's really no way to get a "smoother" circle because computer displays can only display rasterized images. The only way to get a smoother circle is to increase the canvas size that the circle is being drawn to. Anti-aliasing can help, but at some point it will stop working.
Re: Drawing circles with smoother lines?
Anti-aliasing doesn't "stop working". It's a trade-off of sharpness for smoothness.
db
Re: Drawing circles with smoother lines?
True, maybe I should have said becomes less effective :P
Trying to anti-alias a circle 2x2 pixels will only make the square draw lighter