Change brightness of jframe

耗尽温柔 提交于 2019-12-11 04:49:33

问题


I have a program, and it runs in a jframe in full screen exclusive mode. I am trying to change the brightness of the jframe. I was wondering how i would implement this. I thought it might be possible to change all the colors of the images getting drawn to the jframe and make them brighter, but it still does not change how bright the screen actually is. How do programs normally implement something like this.


回答1:


At the end of your draw loop:

g.setColor(new Color(0, 0, 0, 0.5f)); // 50% darker (change to 0.25f for 25% darker)
g.fillRect(0, 0, width, height);



回答2:


I'm not sure if this is the best way, but it works. Override the public void paint(Graphics g)method of your JPanel, then first call the super.paint(g); and paint a transparent black rectangle above it.

Something like this:

private static Color BG = new Color(0, 0, 0, 100);

@Override
public void paint(Graphics g) {
    super.paint(g);
    g2.setColor(BG);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.dispose();
}

Change the Color with a new value instead of 100 to change the darkness.



来源:https://stackoverflow.com/questions/16368208/change-brightness-of-jframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!