WVGA800 上的 Android OutOfMemoryError,而不是任何小屏幕格式
当我尝试在运行低于 WVGA800 的模拟器上解码位图时,它工作正常(包括手机),但在较大的屏幕上,它会抛出 OutOfMemoryError
为什么会这样?屏幕越大的手机内存会越大吗?
private Bitmap getBitmap(int assetKey) { return BitmapFactory.decodeResource(mContext.getResources(), assetKey); }
When I try and decode a bitmap on an emulator running less than WVGA800 it works fine (phones included) but on larger screens it throws a OutOfMemoryError
Why would that be? would phones with larger screens have more memory?
private Bitmap getBitmap(int assetKey) { return BitmapFactory.decodeResource(mContext.getResources(), assetKey); }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显示屏较大的手机并不总是比显示屏较小的手机拥有更多的内存。解码后的位图需要大量内存,每个像素需要 4 字节内存。
一般来说,如果位图太大,则最好对位图进行下采样。您可以轻松地做到这一点:
Phones with larger displays don't always have more memory than phones will smaller displas. Decoded bitmaps take a lot of of memory, 4 bytes of memory per pixel.
In general it is a good idea to downsample the bitmap if they are too large. You can do this easily:
通常,将数据分解为样本是一个很好的做法,以避免内存异常。您可以查看以下链接。你必须使用大于 1 的sampleSize。我已经按照这篇文章解决了我的问题。
将图像加载到 Bitmap 对象时出现奇怪的内存不足问题
It's generally a good practice to break the data in to samples, to avoid memory exception. you can see the following link for that. you have to use sampleSize more than 1. I have resolved my issues by following this post.
Strange out of memory issue while loading an image to a Bitmap object