bitmap size exceeds VM budget in android

后端 未结 5 683
一整个雨季
一整个雨季 2021-01-03 16:49

Getting this

05-25 23:55:59.145: ERROR/AndroidRuntime(3257): java.lang.OutOfMemoryError: bitmap size exceeds VM budget

at this code of min

相关标签:
5条回答
  • 2021-01-03 17:17

    hi @user418366 i was having the same problem when dealing with images what you can do is if you are using the emulator you can rise the max VM application Heap size so that you can get override of this problem or else as told by all try to compress the size of the image make sure that it was a loss less compression

    0 讨论(0)
  • 2021-01-03 17:18

    I ran into a similar problem when selecting images from my EVO ... off the SD Card. The camera saves those images at over 1MB a piece, and in some cases close to 3 MB. Ironically, the size of the bitmap the Intent sends to you when "taking a picture" is only about 40 Kb.

    The solution I came up with was:

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 2;    // this will cut the sampling by 50%
    Bitmap bitmap = BitmapFactory.decodeFile( imageFilePath, options );
    

    I was able to take pictures and cut them down to less than 100 Kb by increasing the factor number, and the images were still pretty good quality.

    The bottom line here is it prevented OOME errors, and thus prevent me from crushing the JVM by exceeding the heap allocation. Simple - effective.

    You might find this an interesting read also: BitmapFactory OOM driving me nuts

    0 讨论(0)
  • 2021-01-03 17:19

    Android has a relatively limited amount of spare of memory for bitmaps (which can get smaller depending on what else is going on in the device). So the other answers are correct...

    • scale the bitmap down (in pixels or resolution)
    • only display the subset of teh bitmap that is visible to the user.

    Check out Displaying a bitmap of arbitrary size without running out of memory for background on what's going on under the covers - which might help you avoid the OOM.

    0 讨论(0)
  • 2021-01-03 17:34

    If the image is really big then you should just display the parts you need.

    0 讨论(0)
  • 2021-01-03 17:37

    Make the bitmap smaller in resolution and potentially use a different file format..

    0 讨论(0)
提交回复
热议问题