为什么在Jlabel不能正常显示图片,谢谢:)
为什么在Jlabel不能正常显示图片,谢谢:)
首先在JLabelA显示图片,而后提取到数据流,在JLabelB显示图片,但是什么也没有,为什么?
代码如下:
ImageIcon imag = new ImageIcon("d:\\1.jpg");
JLabelA.setIcon(imag);
ImageIcon imageIcon = (ImageIcon) JLabelA.getIcon();
Image image = imageIcon.getImage();
BufferedImage bi = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
java.awt.Graphics g = bi.getGraphics();
g.drawImage(bi, 0, 0, null);
output = new ();
try {
ImageIO.write(bi, "JPG", output);
} catch (IOException e1) {
e1.printStackTrace();
}
byte[] buff = output.toByteArray();
InputStream is = new (buff);
Image image1 = null;
try {
image1 = ImageIO.read(is);
} catch (IOException e1) {
e1.printStackTrace();
}
ImageIcon smallIcon = new ImageIcon(image1);
JLabelB.setIcon(smallIcon);