[英]Wierd anti-aliasing in java graphics
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).起初,用不同的颜色,我以为是错觉,(打开和关闭下面注释的 CHECK_# 行)。 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).除了
fill
(填充内部)外,还要draw
(绘制轮廓)。 I am moving on thin ice, but you might do something with the pen stroke width.我在薄冰上移动,但你可以用笔划宽度做一些事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.