【发布时间】:2014-11-09 06:19:52
【问题描述】:
我已经创建了具有从 URL 解码的图像的 android 应用程序。将 URL 解码为位图时出现以下错误。它发生在随机电话上。最好的情况是不发生错误。
以下是错误:
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeStream(BitmapFactory.java)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:663)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:735)
这是我用来解码图片网址的代码:
Bitmap mIcon11 = null;
String filePath = imageURL;
InputStream in = null;
in = new java.net.URL(filePath).openStream();
BitmapFactory.Options o = new BitmapFactory.Options();
o.inSampleSize = 8;
o.inJustDecodeBounds = true;
o.inPurgeable = true;
mIcon11 = BitmapFactory.decodeStream(in);
return mIcon11;
无论如何我都不希望它崩溃。
请帮忙
【问题讨论】:
-
在对位图进行任何操作之前,您必须通过 android 的 Loading Large Bitmaps Efficiently 部分developer.android.com/training/displaying-bitmaps/…
-
@almasshaikh 我已将其插入以进行回收并发布。让我们看看