当前位置:   article > 正文

android 报错java.lang.outofmemoryerror_android – java.lang.OutOfMemoryError:无法分配...

android java.lang.outofmemoryerror

这是你如何使用BitmapFactory.Options:

final BitmapFactory.Options options = new BitmapFactory.Options();

options.inJustDecodeBounds = true;

options.inSampleSize = 2;

options.inJustDecodeBounds = false;

options.inTempStorage = new byte[16 * 1024];

Bitmap bmp = BitmapFactory.decodeFile(picturePath,options);

Bitmap resizedBitmap = Bitmap.createScaledBitmap(bmp, 960, 730, false);

您还可以通过编写自定义函数来计算位图的inSampleSize.

您可以通过在清单中添加android:largeHeap =“true”来增加分配给您的应用程序的内存.

注意:增加应用程序的堆不被认为是理想的解决方案.

以下是谷歌提取的解释,

However, the ability to request a large heap is intended only for a

small set of apps that can justify the need to consume more RAM (such

as a large photo editing app). Never request a large heap simply

because you’ve run out of memory and you need a quick fix—you should

use it only when you know exactly where all your memory is being

allocated and why it must be retained. Yet, even when you’re confident

your app can justify the large heap, you should avoid requesting it to

whatever extent possible. Using the extra memory will increasingly be

to the detriment of the overall user experience because garbage

collection will take longer and system performance may be slower when

task switching or performing other common operations.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/443832
推荐阅读
相关标签
  

闽ICP备14008679号