我目前正在使用 swing 在 java 中设计吃豆人。我有使用以下语句在屏幕上绘制的 PNG 图像。
wall = new ImageIcon(GamePanel.class.getResource("wall.png")).getImage();
g2d.drawImage(wall, x, y, this);
我遇到的问题是,它似乎渲染了实际文件的非常低的颜色深度。看起来它确实保留了透明度(灰色背景是面板背景颜色),但它失去了颜色深度。
The actual image looks like this: When running, it looks like this:
有没有人有办法解决吗?谢谢!
第二张图片中似乎肯定有问题。在黑色 BG 上看到它,它看起来非常不同 - 没有“光环”。
import java.awt.*;
import java.net.URL;
import javax.swing.*;
public class TestYellowDotImage {
public static JLabel getColoredLabel(Icon icon, Color color) {
JLabel label = new JLabel(icon);
label.setBackground(color);
label.setOpaque(true);
return label;
}
public static void main(String[] args) throws Exception {
URL url = new URL("https://i.stack.imgur.com/1EZVZ.png");
final Icon icon = new ImageIcon(url);
Runnable r = new Runnable() {
@Override
public void run() {
JPanel gui = new JPanel(new GridLayout(0, 4));
gui.add(new JLabel(icon));
gui.add(getColoredLabel(icon, Color.BLACK));
gui.add(getColoredLabel(icon, Color.WHITE));
gui.add(getColoredLabel(icon, Color.RED));
JOptionPane.showMessageDialog(null, gui);
}
};
// Swing GUIs should be created and updated on the EDT
// http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html
SwingUtilities.invokeLater(r);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)