private JLabel labelFoto;
labelFoto = new JLabel("imagen.jpg");
Icon icon = labelFoto.getIcon();
byte[] b = icon; // como resolver ?
[Resolvido] Converter Icon para byte[]
2 Respostas
vc pode fazer o icon para image e depois para byte array
static Image iconToImage(Icon icon) {
if (icon instanceof ImageIcon) {
return ((ImageIcon)icon).getImage();
} else {
int w = icon.getIconWidth();
int h = icon.getIconHeight();
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
BufferedImage image = gc.createCompatibleImage(w, h);
Graphics2D g = image.createGraphics();
icon.paintIcon(null, g, 0, 0);
g.dispose();
return image;
}
}
ok.
Resolvido.
Grato !