【发布时间】:2017-01-24 01:24:14
【问题描述】:
我正在构建一个 android 应用程序,我需要从 URL 下载 gif 图像并存储在字节数组中。一直在使用位图工厂类,但它一直返回 null。我将字节数组存储到 sqlite,然后检索和显示。
urlConnection = (HttpURLConnection) url.openConnection();
InputStream is = urlConnection.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
//We create an array of bytes
byte[] data = new byte[4094];
int current = 0;
while((current = bis.read(data,0,data.length)) != -1){
buffer.write(data,0,current);
}
我什至尝试使用 Bitmap.Factory 进行转换,但返回空值。
【问题讨论】:
标签: android inputstream gif