我正在编写一个程序来保存互联网上的图像,但其中一些图像最终呈灰色。或者它只是真正的灰色图标,因为如果我打开图像,它不是灰色的。从URL保存的图像部分是灰色的
这里是我用来保存图片的方法:
public static void saveImage(String imageUrl, String destinationFile) throws IOException{
URL url = new URL(imageUrl);
InputStream is = url.openStream();
OutputStream os = new FileOutputStream(destinationFile);
byte[] b = new byte[2048];
int length;
while ((length = is.read(b)) != -1) {
os.write(b, 0, length);
}
is.close();
os.close();
}
我相信问题是,即时通讯关闭流之前的图像已经被完全写入。有没有什么方法可以检查它是否完成或者什么?
代码看起来不错。 “图标”是什么意思?您可以在完成写入之前提供图片/图标吗?您想等到saveImage方法完成。 – Thilo 2012-04-26 11:05:35