Is there any better way to get the Icon of a JLabel in a container as a BufferedImage whithout multiple casts?
Component[] components = container.getComponents();
BufferedImage image = ((BufferedImage) ((ImageIcon) ((JLabel) components[i]).getIcon()).getImage());
In order to get a buffered image from a JLabel, you do the following (which is what your original answer asked):
Icon icon = label.getIcon();
BufferedImage bi = new BufferedImage(icon.getIconWidth(),
icon.getIconHeight(),BufferedImage.TYPE_INT_RGB);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With