【发布时间】:2015-11-23 09:48:39
【问题描述】:
我想从一个数组列表中显示图像视图中的图像,该数组包含一个 URL 列表,如
private String imageUrls[] = {"http://theopentutorials.com/totwp331/wp-content/uploads/totlogo.png",
"http://theopentutorials.com/totwp331/wp-content/uploads/totlogo.png",
"http://theopentutorials.com/totwp331/wp-content/uploads/totlogo.png"
};
当我转到下一张图片时,它会显示OutOfMemoryException。
请帮忙
我使用的代码如下
protected Bitmap doInBackground(String... urls) {
Bitmap bitmap = null;
try {
String url = urls[0];
InputStream in = null;
try {
in = new java.net.URL(url).openStream();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
bitmap = BitmapFactory.decodeStream(in);
} catch (OutOfMemoryError e) {
Log.e("MyApp", e.getMessage());
}
return bitmap;
}
protected void onPostExecute(final Bitmap result) {
handler=new Handler();
handler.post(new Runnable() {
@Override
public void run() {
bmImage.setImageBitmap(result);
}
});
}
【问题讨论】:
-
图片太大了
-
在 manifest 中使用 largeHeap,但是看看你的图片尺寸...
-
是的,我需要显示图像。有没有办法处理这个异常?请帮助
-
看看毕加索图书馆square.github.io/picasso除非真的有必要,否则不要尝试自己下载/缓存/显示图像。
标签: android