Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2019-12-09:请谈谈如何加载Bitmap并防止内存溢出? #207

Open
Moosphan opened this issue Dec 9, 2019 · 4 comments
Open

2019-12-09:请谈谈如何加载Bitmap并防止内存溢出? #207

Moosphan opened this issue Dec 9, 2019 · 4 comments

Comments

@Moosphan
Copy link
Owner

Moosphan commented Dec 9, 2019

No description provided.

@guosen
Copy link

guosen commented Dec 12, 2019

首先我们 要知道bitmap内存是怎么计算的例子:

手机屏幕大小 1080 x 1920(inTarget = 420),加载 xhdpi (inDensity = 320)中的图片 1920 x 1080,scale = 420 / 320,
最总我们可以得知 他的占用内存 1418 * 2520 * 4
很明显 被放大了。
防止内存溢出:1对图片进行内存压缩;
2.高分辨率的图片放入对应文件夹;
3.内存复用
4.及时回收

@Alex-Cin
Copy link

PS:
新版本的 bitmap 单独存放在 native 堆, 不在 java 堆了;
使用 inBitmap 属性, Glide 也在用;
@guosen

@fuusy
Copy link

fuusy commented Mar 31, 2020

这篇文章可以参考下https://juejin.im/entry/5e76df8a518825490b64a506

@mlinqirong
Copy link

先通过BitmapFactory.Options 设置inJustDecodeBounds 不占用内存来获取图片信息
判断是否为大图 根据使用场景计算缩放比较 inJustDecodeBounds设置为false 传递inSampleSize缩放比例压缩图片

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants