Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JLabel get Image

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());
like image 308
Sp0tlight Avatar asked Nov 03 '22 19:11

Sp0tlight


1 Answers

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);
like image 184
nook Avatar answered Nov 09 '22 13:11

nook