Image OutOfMemoryError

时间:2011-12-29 17:03:19

标签: android out-of-memory

我想在ImageView中加载图像。所以,我做了一个:

Intent gallery = new Intent();
    gallery.setType("image/*");
    gallery.setAction(Intent.ACTION_GET_CONTENT);

然后我们回到URI和媒体,然后将图像加载到ImageView中。

但是如果图像尺寸很大,我有以下例外:

12-29 17:51:25.240: ERROR/AndroidRuntime(24339): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at android.graphics.Bitmap.nativeCopy(Native Method)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at android.graphics.Bitmap.copy(Bitmap.java:315)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at na.gioacchinodelprete.android.signatureimage.SignatureImageActivity.writeOnDrawable(SignatureImageActivity.java:290)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at na.gioacchinodelprete.android.signatureimage.SignatureImageActivity.onActivityResult(SignatureImageActivity.java:258)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at android.app.Activity.dispatchActivityResult(Activity.java:3934)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:2578)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at android.app.ActivityThread.access$2000(ActivityThread.java:117)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:965)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at android.os.Looper.loop(Looper.java:123)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at android.app.ActivityThread.main(ActivityThread.java:3691)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at java.lang.reflect.Method.invokeNative(Native Method)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at java.lang.reflect.Method.invoke(Method.java:507)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
12-29 17:51:25.240: ERROR/AndroidRuntime(24339):     at dalvik.system.NativeStart.main(Native Method)

帮帮我?? !!!

2 个答案:

答案 0 :(得分:4)

以前曾多次询问过这个问题。您需要对图像进行缩减采样,以便可以在ImageView中显示。有关解决方案,请参阅this question。请记住,图像需要W x H x 4 bytes存储在内存中并显示。

答案 1 :(得分:-2)

错误清楚地描述了dalvik VM不支持您的图像大小。如果您的图片尚未支持分辨率,请将其转换并尝试。如果已经在该分辨率中,则需要编辑和缩小图像的大小。