Answer the question
In order to leave comments, you need to log in
Why is Canvas not displaying an image?
File file = chooser.getFile().showOpenDialog(new Stage());
String path;
try {
path = file.getPath();
FileInputStream fileInputStream = new FileInputStream(path);
javafx.scene.image.Image image = new javafx.scene.image.Image(fileInputStream);
Canvas canvas = new Canvas();
GraphicsContext graphicsContext = canvas.getGraphicsContext2D();
graphicsContext.drawImage(image, 0, 0);
} catch (Exception e){
e.printStackTrace();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question