Android 从internet加载图像时位图大小超过VM预算?
我正在尝试在imageview中显示来自internet的图像 这引起了下面的错误任何一个引导我的人我在这里犯了什么错误 公共位图显示LiveImage(字符串ImageSrc) { 位图bm; 试试{Android 从internet加载图像时位图大小超过VM预算?,android,out-of-memory,Android,Out Of Memory,我正在尝试在imageview中显示来自internet的图像 这引起了下面的错误任何一个引导我的人我在这里犯了什么错误 公共位图显示LiveImage(字符串ImageSrc) { 位图bm; 试试{ URL aURL = new URL(ImageSrc); URLConnection conn = aURL.openConnection();
URL aURL = new URL(ImageSrc);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = null;
try
{
is= conn.getInputStream();
}catch(IOException e)
{
return null;
}
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
} catch (IOException e) {
return null;
}
return bm;
}
logcat
11-12 21:45:22.509: ERROR/AndroidRuntime(7118): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
11-12 21:45:22.509:
ERROR/AndroidRuntime(7118): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
11-12 21:45:22.509:
ERROR/AndroidRuntime(7118): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:476)
11-12 21:45:22.509:
ERROR/AndroidRuntime(7118): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:537)
11-12 21:45:22.509:
ERROR/AndroidRuntime(7118): at com.Finditnear.FindItNearActivityWithoutMenu.DisplayLiveImage
(FindItNearActivityWithoutMenu.java:149)
11-12 21:45:22.509: ERROR/AndroidRuntime(7118): at com.Finditnear.ViewSingleImage$1.run
(ViewSingleImage.java:88)
任何帮助都将不胜感激。您试图加载的图像有多大?如果它将导致一个大位图,您的内存将耗尽,因为Android只为您的应用程序提供有限的内存(我认为在2.2设备上是16MB或24MB)。如果它是一个大图像,请签出