0
執行以下測試 - 青色矩形顯示居中。這是預期的結果。但是,爲什麼視口的minX和minY必須是負值?JavaFX節點快照X/Y參數必須爲負
public class NodeScreenshotTest extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
@Override
public void start(Stage stage)
{
stage.setScene(new Scene(createContent()));
stage.getScene().setFill(Color.BEIGE);
stage.setTitle(getClass().getSimpleName());
stage.show();
}
private Parent createContent()
{
BorderPane content = new BorderPane();
Rectangle rectangle = new Rectangle(50, 50);
rectangle.setFill(Color.AQUA);
SnapshotParameters params = new SnapshotParameters();
params.setFill(Color.YELLOW);
// Viewport x/y negative???
params.setViewport(new Rectangle2D(-15, -15, 80, 80));
ImageView iv = new ImageView(rectangle.snapshot(params, null));
content.setCenter(iv);
return content;
}
}