[Resolvido] Converter Icon para byte[]

2 respostas
vpmaciel1981
private JLabel labelFoto;

labelFoto = new JLabel("imagen.jpg");
Icon icon = labelFoto.getIcon();

byte[] b = icon; // como resolver ?

2 Respostas

nextuser

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; } }

vpmaciel1981

ok.

Resolvido.

Grato !

Criado 25 de abril de 2011
Ultima resposta 26 de abr. de 2011
Respostas 2
Participantes 2