-1

I want to load an image in an ImageView. So, I make a:

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

and then we are back to the URI and the Media, followed by loading the image into an ImageView.

But if the image is large in size, I have the following exception:

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)

Help me??!!!

Mat Nadrofsky
  • 8,289
  • 8
  • 49
  • 73
  • This problem has been answered several time, no need to re ask it. – slayton Dec 29 '11 at 20:47
  • possible duplicate of [Android: Strange out of memory issue](http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue) – slayton Dec 29 '11 at 20:47

2 Answers2

4

This has been asked many times before. You need to downsample the image so it can be displayed in your ImageView. See this question for solutions. Remember that images need W x H x 4 bytes to be stored in memory and displayed.

Community
  • 1
  • 1
dmon
  • 30,048
  • 8
  • 87
  • 96
-2

Error clearly describing that your image size is not supported by dalvik VM. If your image is not already in supported resolution, please convert it and try. If already in that resolution , you need to edit and reduce the size of image.

kosa
  • 65,990
  • 13
  • 130
  • 167
  • The format of the image is irrelevant, only the resolution matters. – dmon Dec 29 '11 at 17:09
  • Agree, that is what I meant by using bitmap to jpeg. Edited my answer. Thanks for pointing. – kosa Dec 29 '11 at 17:14
  • @thinksteep A tip from when I started helping more in the community and answering more questions: give more links and / or sample code (this leads to more upvotes as well). How does he edit it and reduce the size? A three sentence answer with no code or references is not really that helpful. Anyway, just trying to pass on what was told to me when I started helping. :) – Jack Dec 29 '11 at 17:39
  • @Jack, thanks for your suggestion. Will do. Remember, when I did that last time, you down voted. – kosa Dec 29 '11 at 19:36