JavaFX - css 添加具有透明度的背景图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20164971/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaFX - css adding background image with transparency
提问by baxbear
I want to add an image (png) this way:
我想以这种方式添加图像(png):
#leftCorner {
-fx-background-image: url("images/backgroundTrain2.png");
-fx-background-repeat: stretch;
-fx-background-size: 150.0 71.0;
-fx-background-position: center center;
}
the problem is that I loose the transparency of the white part of the image. Can somebody tell me what I can do that it stays transparent?
问题是我失去了图像白色部分的透明度。有人能告诉我我能做些什么来保持透明吗?
thats the picture i try to add as background
这就是我尝试添加为背景的图片
采纳答案by Aakash Goyal
I use -fx-background-color:transparent
to set pngs on my Buttons and transparency works. Try this.
我-fx-background-color:transparent
过去常常在我的按钮和透明度上设置 png。尝试这个。
回答by Tom
-fx-opacity: 0.5;
-fx-不透明度:0.5;
Add this to your ID in fx css file
将此添加到您在 fx css 文件中的 ID