Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Save ImageIcon to file

807605Jun 13 2007 — edited Jun 13 2007
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 11 2007
Added on Jun 13 2007
1 comment
365 views