0
我正在使用javafx制作棒球游戏应用程序。我想在棒球场上展示一名棒球运动员。但是,有一个白盒子限制了球员并阻挡了棒球场的视野。 如何使用javafx删除此框?使图像的一部分透明
import java.io.File;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class BaseballView extends Application {
@Override
public void start(Stage stage) {
StackPane root = new StackPane();
String image = this.getClass().getResource("baseball_field.jpg")
.toExternalForm();
root.setStyle(" -fx-background-image: url('" + image + "'); "
+ "-fx-background-position: center center; "
+ "-fx-background-repeat: stretch;");
stage.setScene(new Scene(root, 340, 340));
stage.setTitle("Baseball");
ImageView player = new ImageView();
player.setTranslateX(250);
player.setImage(new Image("player.bmp"));
root.getChildren().add(player);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
我可以将文件类型更改为任何东西。我下载的图片是一个bmp。我可以使用paint来更改文件类型。 – Halbort
请勿将其更改为“任何内容”,将其更改为PNG并保留透明度。 BMP非常有限,例如, G。只有32位BMP图像支持透明度。然后,图像阅读器需要支持这一点。此外,如果您需要关于该特定图像的帮助,则应该将图像置于您的问题中,因为这是问题所在。 – Roland
原始图像有空白。 – Halbort