使用javafx显示具有透明背景的PNG文件 [英] Showing a PNG file with transparent background using javafx
本文介绍了使用javafx显示具有透明背景的PNG文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我实际上是在不使用javaFX的情况下在启动屏幕上工作的,everythink可以正常工作,但是我想在启动屏幕上显示带有透明背景的png图像,但无法执行此操作,有人可以告诉我是否可以这样做是否从JavaFX Scene Builder中获取它?
Am actually working on a splash Screen unsing javaFX, everythink works fine but I want to show a png image with a transparent background on the splash screen, but am unable to do it, can someone please tell me if it's possible to do it from JavaFX Scene Builder or not ?
推荐答案
我有点着急,但是下面是一个简单的示例,向您展示如何通过将StageStyle设置为Transparent和场景来完成此操作.填充为透明"颜色.
I'm in a bit of a rush, but below is a quick example to show you how it can be done by setting the StageStyle to Transparent and the scene fill to the color "transparent".
@Override
public void start(Stage aStage) throws Exception {
Pane root = new Pane();
ImageView img = new ImageView();
img.setImage(new Image(getClass().getResource("pathToYourPngLocatedInYourResourcesFolder.png").toExternalForm()));
root.getChildren().add(img);
Scene scene = new Scene(root, 500, 500);
scene.setFill(Color.TRANSPARENT);
aStage.initStyle(StageStyle.TRANSPARENT);
aStage.setScene(scene);
aStage.show();
}
让我知道它是如何工作的:)
Let me know how it works out :)
这篇关于使用javafx显示具有透明背景的PNG文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文