Save ImageIcon to file
Hello all,
Could someone teach me to save and ImageIcon class to an file. I've tried ImageIO.write, but that doesn't accept an ImageIcon class. Tried to use BufferedImage, but that doesn't accept ImageIcon either.
ImageIcon icon = new ImageIcon(file.getAbsolutePath(), "Test");
int h = icon.getIconHeight();
int w = icon.getIconWidth();
int hnew, wnew;
if (h > w) {
hnew = jLabelPict.getHeight();
wnew = w / (h / jLabelPict.getHeight());
} else {
wnew = jLabelPict.getHeight();
hnew = h / (w / jLabelPict.getHeight());
}
Image img = icon.getImage().getScaledInstance(
wnew, hnew, Image.SCALE_FAST);
icon.setImage(img);
jLabelPict.setIcon(icon);
jLabelPict.setText("");
jTextField.setText(file.getAbsolutePath().toString());
.....
At this point the file should be saved.
.....
Many thanks & regards

