0
我正在構建一個android應用程序,我需要從一個URL下載一個gif圖像並存儲在一個字節數組中。一直使用位圖工廠類,但它一直返回null。我將字節數組存儲到sqlite然後檢索並顯示。下載Streamed gif文件並存儲在字節數組中
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,但返回空值。