L
Larry Coon
I'm confused about how to create a BufferedImage.
I'm trying to use a JFileChooser to select a file,
and load the selected (image) file into a
BufferedImage. I'm using this approach:
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showOpenDialog(MyClass.this);
if (result == JFileChooser.CANCEL_OPTION) return;
File file = fileChooser.getSelectedFile();
if (file == null || file.equals("")) return;
BufferedImage image = (BufferedImage)
Toolkit.getDefaultToolkit().createImage(file.getPath());
The downcast doesn't work -- I get a ClassCastException.
But I don't see another way to get a BufferedImage from
an Image. Am I missing something obvious?
I'm trying to use a JFileChooser to select a file,
and load the selected (image) file into a
BufferedImage. I'm using this approach:
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showOpenDialog(MyClass.this);
if (result == JFileChooser.CANCEL_OPTION) return;
File file = fileChooser.getSelectedFile();
if (file == null || file.equals("")) return;
BufferedImage image = (BufferedImage)
Toolkit.getDefaultToolkit().createImage(file.getPath());
The downcast doesn't work -- I get a ClassCastException.
But I don't see another way to get a BufferedImage from
an Image. Am I missing something obvious?