当我试图在黑色背景上画白色字母时,我注意到一些奇怪的东西。
public WhiteOnBlackPanel() { setBackground(Color.BLACK); } public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(new Color(255,255,255)); g.drawString("Hello World",100,100); g.drawLine(0,0,100,100); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.add(new WhiteOnBlackPanel()); frame.setTitle("Hello World"); frame.setSize(600,400); frame.setLocation(100,100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); // The frame is visible from now on }! 不要看图像中的代码,只看框架!
给我这个:
然而,线条画得很好。
当我采用不同但非常接近的颜色(254,255,255)时,我得到了这个
为什么java.awt.Graphics阻止绘制纯白色(255,255,255)字母(即使它是在黑色背景上)?
蒂亚,查理
When I was trying to draw white letters on a black background I noticed something weird.
public WhiteOnBlackPanel() { setBackground(Color.BLACK); } public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(new Color(255,255,255)); g.drawString("Hello World",100,100); g.drawLine(0,0,100,100); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.add(new WhiteOnBlackPanel()); frame.setTitle("Hello World"); frame.setSize(600,400); frame.setLocation(100,100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); // The frame is visible from now on }! Don't look at the code in the images, just look at the frame !
Gave me this:
Lines, however, were being drawn well.
When I took a different, but very close, color (254, 255, 255), I got this
Why is java.awt.Graphics blocking pure white (255,255,255) letters from being drawn (even when it is on a black background) ?
Tia, Charlie
最满意答案
jdk1.8.0_20中的一个错误,至少在Linux(Ubuntu)中:0xFFFFFFFF显示为BLACK。 更改alpha或其中一个RGB值会导致“几乎为白色”。
jdk1.7.0_67在同一系统上运行正常。
检查所有形式的setColor。
后来发现bug报告: JDK-8054638:没有涂上白色
受影响的版本:8u11,8u25
这个bug只影响Linux; 在Windows上一切正常。
A bug in jdk1.8.0_20, at least in Linux (Ubuntu): 0xFFFFFFFF appears as BLACK. Changing alpha or one of the RGB values results in "almost white".
jdk1.7.0_67 works fine on the same system.
Checked all forms of setColor.
Later Found that bug is reported: JDK-8054638 : White color is not painted
Affected Versions: 8u11,8u25
This bug only affects Linux; on Windows everything works fine.
更多推荐
发布评论