I am attempting to display an image file as soon as it is selected from a file chooser. The file chooser is restricted to .png and .jpg files with the selected files being stored in a variable of type File. To do this I have set up an ImageView, and I wish to set the image with this new file only problem is it is of type File not Image.
How can this be achieved? Code so far...
public void fileSelection(){
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Select Profile Picture");
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Image Files", "*.png", "*jpg"));
File selectedFile = fileChooser.showOpenDialog(null);
File selectedFileInput = selectedFile;
if(selectedFile != null) {
selectedFileOutput.setText("File selected: " + selectedFile.getName());
previewPicture.setImage();
} else {
selectedFileOutput.setText("Please select a profile picture...");
}
}