简体   繁体   English

Java使用rgb设置Color.color上的透明度

[英]Java set transparency on Color.color WITHOUT using rgb's

I'm woundering, is there a way to set transparency on a color without using rgb's. 我想知道,有没有办法在不使用rgb的情况下设置颜色的透明度。 For example you can do this 例如,你可以这样做

Color color = new Color(255,255,255,Transparency) 

but I want to use it this way 但我想用这种方式使用它

Color = new Color(Color.red,Transparency)

It doesn't look like there's any such method or constructor at the moment, but it's dead easy to write a helper method: 目前看起来没有任何此类方法或构造函数,但编写辅助方法很容易:

public static Color newColorWithAlpha(Color original, int alpha) {
    return new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
}

You can import that statically, at which point you'd have: 您可以静态导入,此时您可以:

Color color = newColorWithAlpha(Color.red, alpha);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM