1
我要显示的图像,因为它正在下载,我有URL,我想获得这样的图像部分:逐行图像摆动
InputStream openStream = url.openStream();
DataInputStream dis = new DataInputStream(new BufferedInputStream(openStream));
ByteArrayOutputStream os = new ByteArrayOutputStream();
while ((s = dis.read(b)) != -1) {
os.write(b , 0, s);
support.firePropertyChange("stream", null, os);
}
这样,任何一个听众获得流和创建图像时,这样说:
if("stream".equals(evt.getPropertyName())){
try {
ByteArrayOutputStream stream = (ByteArrayOutputStream) evt.getNewValue();
byte[] byteArray = stream.toByteArray();
stream.flush();
Image createImage = Toolkit.getDefaultToolkit().createImage(byteArray);
this.getContentPane().add(new JLabel(new ImageIcon(createImage)));
} catch (IOException ex) {
Logger.getLogger(ImageTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
但是,我得到一个“JPEG文件sun.awt.image.ImageFormatException过早结束:JPEG数据流内没有图像”的错误,该图像是一个JPG图像格式,是否有任何已知的类似的库或方法?