如何在图形中以透明颜色制作矩形?
我试图在我的应用程序上以红色阴影绘制一个矩形,但我需要将其设置为透明,以便其下方的组件仍会显示。然而我仍然希望一些颜色仍然会显示出来。我绘制的方法如下:
protected void paintComponent(Graphics g) {
if (point != null) {
int value = this.chooseColour(); // used to return how bright the red is needed
if(value !=0){
Color myColour = new Color(255, value,value );
g.setColor(myColour);
g.fillRect(point.x, point.y, this.width, this.height);
}
else{
Color myColour = new Color(value, 0,0 );
g.setColor(myColour);
g.fillRect(point.x, point.y, this.width, this.height);
}
}
}
有谁知道如何使红色阴影有点透明?但我不需要它完全透明。
I'm trying to paint a rectangle on my application in a red shade but I need to make it sort of transparent so that the component under it will still show. However I still want that some colour will still show. The method where I'm drawing is the following:
protected void paintComponent(Graphics g) {
if (point != null) {
int value = this.chooseColour(); // used to return how bright the red is needed
if(value !=0){
Color myColour = new Color(255, value,value );
g.setColor(myColour);
g.fillRect(point.x, point.y, this.width, this.height);
}
else{
Color myColour = new Color(value, 0,0 );
g.setColor(myColour);
g.fillRect(point.x, point.y, this.width, this.height);
}
}
}
Does anyone know how I can make the red shade a bit transparent? I don't need it completely transparent though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅
Color
构造函数,采用 4 个参数(int
或float
)以了解更多详细信息。See the
Color
constructors that take 4 arguments (of eitherint
orfloat
) for further details.试试这个:(但它适用于 Graphics2D 对象,不适用于 Graphics)
Try this: (but it will works for Graphics2D objeccts not for Graphics)