A
A
Anton @ Lyalin2017-04-26 10:54:06
JavaFX
Anton @ Lyalin, 2017-04-26 10:54:06

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 question

Ask a Question

731 491 924 answers to any question