Skip to main content

anti-aliasing anomaly?

3 replies [Last post]
rtwillemsen
Offline
Joined: 2007-02-23

Hi

I have a applet (see code) below which behaves a little strange.
It draws 2 circles with a basic stroke as its 'border'. The 1st circle is first filled then drawn; the 2nd circle the other way round. Notice how the border of the right circle seems to be thinner on the left side than on the right side ...
If you comment the g2.setRenderingHint-statement, the borders seems to be equally thick on both sides ??
I am running the applet under JDK 1.6.0.

Hope someone can provide some insight.

regards rob willemsen

********************** sample applet
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.geom.Ellipse2D;

public class FillStrokeAnomaly extends java.applet.Applet {

public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;

Ellipse2D.Double e1 = new Ellipse2D.Double(10,10,160,160);
Ellipse2D.Double e2 = new Ellipse2D.Double(180,10,160,160);
BasicStroke bs = new BasicStroke(7, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 0,
new float[] { 10, 10 }, 3);

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

//first fill, then draw
g2.setPaint(Color.ORANGE);
g2.fill(e1);
g2.setStroke(bs);
g2.setPaint(Color.BLACK);
g2.draw(e1);

//first draw then fill
// draw circle with stroke square, a join bevel, and uses a dash phase
g2.setStroke(bs);
g2.setPaint(Color.BLACK);
g2.draw(e2);
g2.setPaint(Color.ORANGE);
g2.fill(e2);
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rtwillemsen
Offline
Joined: 2007-02-23

has nobody got a clue for me concerning this?

rob willemsen

roman_kennke
Offline
Joined: 2007-02-16

I don't think this has do to with stroking, but with how shapes are stroked. I've derived a slighly simpler test from yours that shows the same problem with AA turned off and a Rectangle2D instead of an Ellipse2D. However, I am also missing a reasonable explanation why this is so, except rounding or accuracy problems in the stroking. Note how a g2.translate(0.5, 0.4) gets rid of the problem.

Interestingly enough, I've created a similar testcase that does practically the same on Cairo (outside of Java land) and shows similar results...

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.geom.Arc2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Ellipse2D;

public class FillStrokeAnomaly extends java.applet.Applet {

public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;

Rectangle2D.Double e1 = new Rectangle2D.Double(10,10,160,160);
Rectangle2D.Double e2 = new Rectangle2D.Double(180,10,160,160);

//first fill, then draw
g2.setPaint(Color.ORANGE);
g2.fill(e1);
g2.setPaint(Color.BLACK);
g2.draw(e1);

//first draw then fill
g2.setPaint(Color.BLACK);
g2.draw(e2);
g2.setPaint(Color.ORANGE);
g2.fill(e2);
}

public static void main(String[] args) {
Frame f = new Frame();
f.add(new FillStrokeAnomaly());
f.setSize(600, 400);
f.setVisible(true);
}
}

rtwillemsen
Offline
Joined: 2007-02-23

Roman,

Thnx for answering.
Where do you put the g2.translate to get rid of the problem? It doesn't seem to work for me ...

rob