Convert Imageicon to Image or Imageicon to Bufferedimage

Asked

Viewed 459 times

0

I’m having trouble finding ways to convert ImageIcon for Image or if possible ImageIcon for BufferedImage in order to be able to save it in the database. I did some research on the internet but the information found is a bit confusing!

1 answer

2


To obtain an instance of Image of a kind Imageicon just use the method getImage():

Image img = seuIcon.getImage();

plain as that ;).

And to convert to BufferedImage, try as suggested in this reply from Soen:

BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB);
Graphics g = bi.createGraphics();
// paint the Icon to the BufferedImage.
icon.paintIcon(null, g, 0,0);
g.dispose();

The ideal would be to save only the image path and itself in some directory of the server, but if you want to continue and save in the bank, usually the format is blob, but you do not need to convert to bufferedimage or image.

  • Thanks! Maybe you can use your example for other applications!

  • I made a File capitulating the Bufferedimage directly inside the Object and then saved with the maximum quality inside the database! Thanks anyway Articuno.. well I’m new here, as I can score it and close the topic?

  • @Falco404 good, "quit" has not, but when the answer is useful to those who ask, the author can accept it by clicking on v On the other hand, this is the only way to demonstrate that the solution has been found. Or the author himself posting, if his solution is quite different from the one who answered.

  • Thank you! I think I get it!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.