在内存使用和性能方面是否有更有效的方法来做到这一点。以下方法下载位图并使用进度调用函数。
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection connection = url.openConnection();
connection.connect();
int fileLength = connection.getContentLength();
InputStream input = new BufferedInputStream(url.openStream());
byte data[] = new byte[1024];
long total = 0;
int count;
while ((count = input.read(data)) != -1) {
total += count;
if(imageInterface != null) {
imageInterface.duringDownload(
imageView, ((int)total * 100 / fileLength));
}
outputStream.write(data, 0, count);
}
byte[] byteArray = outputStream.toByteArray();
Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
input.close();
outputStream.flush();
outputStream.close();
return bitmap;