0
我需要在显示动画时达到“关灯”的效果。目前已经完成透明Jframe,黑色背景,显示器的大小不透明度为50%。那么,这个画布组件应该绘制RGB缓冲图像的RGB A。如何忽略JFrame不透明度?
当JFrame不透明度也影响Canvas时弹出问题,使其半透明。这就是我想要避免的。
//** Window class extends Canvas
public Window(){
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int hostMonitorWidth = gd.getDisplayMode().getWidth();
int hostMonitorHeight = gd.getDisplayMode().getHeight();
Dimension dimension = new Dimension(hostMonitorWidth, hostMonitorHeight);
super.setPreferredSize(dimension);
window = new JFrame();
window.setUndecorated(true);
window.setOpacity(0.55f);
window.setLayout(new GridLayout());
window.setSize(hostMonitorWidth, hostMonitorHeight);
window.add(this);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLocationRelativeTo(null);
window.setVisible(true);
window.requestFocus();
window.setFocusableWindowState(true);
super.createBufferStrategy(3);
}
public void draw(){
BufferStrategy buffer = super.getBufferStrategy();
java.awt.Graphics g = buffer.getDrawGraphics();
g.setColor(Color.BLACK);
g.fillRect(0,0, super.getWidth(), super.getHeight());
g.drawImage(batch.getImage(), 0, 0, super.getWidth(), super.getHeight(), null);
g.dispose();
buffer.show();
}
我已经尝试了以下代码与Jpanel,Layered Panes,Jlabel以及哪些不同的组合。似乎总是保持不透明/抛出无法解释的例外/不能以任何理由工作。
我在做正确的方法吗?我在这里错过了什么?
我已经试过了,好像在研究背景颜色接管画布。你能否证明它应该如何正确完成? –
而且,正如我所说'Canvas'可能不喜欢你在做什么,因为它只有一个不透明的状态(它不支持透明度),如果你想绘制一个半透明的组件,你将需要使用一个Swing而不是基于组件 – MadProgrammer
你最好的建议是什么? –