I came across to this wierd anti-aliasing:
The left shape and the right shape exactly shares the curve part. However, a black curve appears and interrupt the smoothness of the drawing and colors. This is a sample, and it intends to show the issue.
At first, with different colors, I thought it was optical illusion, (turn on and off the commented CHECK_# lines below). But when used the same color, this happened.
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Path2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class darkBorders extends JPanel {
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(Color.BLACK);
//g2.setColor(Color.WHITE); //CHECK_1
g2.fill(g2.getClip());
int r = 100;
g2.translate(this.getWidth() / 2 - r, this.getHeight() / 2 - r);
Path2D p = new Path2D.Double();
p.moveTo(0, 0);
p.lineTo(r, 0);
p.quadTo(2 * r, r, r, 2 * r);
p.lineTo(0, 2 * r);
p.closePath();
g2.setColor(new Color(0xFF9900));
//g2.setColor(new Color(0x00CC66)); //CHECK_2
g2.fill(p);
p.reset();
p.moveTo(2 * r, 0);
p.lineTo(r, 0);
p.quadTo(2 * r, r, r, 2 * r);
p.lineTo(2 * r, 2 * r);
p.closePath();
g2.setColor(new Color(0xFF9900));
g2.fill(p);
g2.dispose();
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setContentPane(new darkBorders());
frame.setSize(500, 300);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Is there anything I can fix this issue? Many thanks in advance.
Besides a fill
(fills the interior) do also a draw
(draws the outline). I am moving on thin ice, but you might do something with the pen stroke width.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.