
我正在做如下图所示的缩放地图
Bitmap resizedBitmap = Bitmap.createScaledBitmap(BitmapFactory.decodefile(picturePath), 960, 730, false);做这个处理我上传图像有时我得到低于类型错误
java.lang.OutOfMemoryError: Failed to allocate a 31961100 byte allocation with 15257484 free bytes and 14MB until OOM请帮帮我怎么解决?
解决方法:
这是你如何使用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.
这是谷歌文档:http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
您可以通过在清单中添加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.
这是文档https://developer.android.com/training/articles/memory.html的完整链接
总结以上是内存溢出为你收集整理的android – java.lang.OutOfMemoryError:无法分配31961100字节分配15257484个空闲字节和14MB直到OOM全部内容,希望文章能够帮你解决android – java.lang.OutOfMemoryError:无法分配31961100字节分配15257484个空闲字节和14MB直到OOM所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)