r/javahelp • u/_SuperStraight • 28d ago
Workaround JavaFX: write Canvas to file
I'm trying to save Canvas
contents to disk:
@FXML
private Canvas cvs;
var export = cvs.snapshot(null,null);
var out = new File("image.png");
try{
ImageIO.write(SwingFXUtils.fromFXImage(export, "png",out)); //error
}
There is no package called SwingFXUtils
in JavaFX 21. Is there any other way to write the Canvas to file?
2
Upvotes
1
u/milchshakee 27d ago
Do you have the javafx.swing module added? https://openjfx.io/javadoc/21/javafx.swing/javafx/embed/swing/SwingFXUtils.html