Android 中基于 1 位的位图
我正在尝试缓存大位图以便在 Android 屏幕上绘图。但现在我面临 OutOfMemoryException,说位图分配超出了 VM 预算。
我需要最小化位图的大小,但无法降低分辨率。对于我的用例,我只需要保存位图的形状并在稍后实际绘制时应用颜色,因此我使用 ALPHA_8 作为位图配置。
我想知道位图中是否有 1 位像素(完全不透明或完全透明)配置,或者任何类似的方式来节省内存?
I am trying to cache big bitmaps for drawing on screen in Android. But now I am facing OutOfMemoryException, say that the bitmap allocation exceeds the VM budget.
I need to minimize the size of the bitmap but I cannot reduce the resolution. For my use case, I need to only save the shape of the bitmap and apply color later when actually drawing, so I am using ALPHA_8 as the bitmap configuration.
I want to know if there is a 1-bit pixel (either completely opaque or completely transparent) configuration in bitmap, or any similar ways to save memory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,将颜色深度从 8 位减少到 1 位会有一点帮助。然而,它并没有真正解决问题,只是推迟了问题的解决。这仅意味着您稍后会获得 OOME,但您仍然会获得它。
考虑将缓存从 RAM 移动到磁盘,并且可以选择在其上添加较小的基于 RAM 的缓存以提高性能。
Reducing the color depth from 8 bits to 1 would, of course, help a little. However, it doesn't really solve the problem but just postpones it. It only means that you'll get the OOME later but you'll still get it.
Consider moving your cache from RAM to disk and, optionally, add a smaller RAM-based cache on top of it to improve performance.