如何减少位图内存使用量的字节数但保持其尺寸 [英] how to reduce the bitmap memory usage byte count but keep its dimensions

查看:138
本文介绍了如何减少位图内存使用量的字节数但保持其尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索并仅找到缩放位图以减小其尺寸和大小的解决方案.但是我正在寻找一种减少位图的内存字节数并且不更改其尺寸的方法.

Searched and only find solutions for scale the bitmap to reduce its dimensions and size. But I am looking for a way to reduce the bitmap's memory byte count and don't change its dimension.

图像来自远程来源,它们不在我们的控制范围内. ,将图像保存到本地设备后,它们将在以后显示为缩略图.注意它经常抛出OOM异常.第一步是从文件加载时将位图缩小到较小的尺寸(例如500x500或300x300),

The images are from remote sources, they are not in our control. , after save the images to device locally, they will be shown as thumbnail later. Noticed it frequently throws OOM exception. The first step was to scale down the bitmap to a smaller dimensions when loading from the file (such as 500x500, or 300x300), here has some suggestions, which helps a little bit. A closer look find the scale downed bitmap may still have large byte count (from a few hundreds k to over one meg).

因为在这种情况下,内存中分辨率较低的位图应该可以,所以有没有办法保持位图的尺寸但减少内存字节数?

Since for this case the bitmap with lower resolution in memory should be ok, so is there a way it can keep the bitmap's dimensions but reduce it memory byte count?

谢谢!

推荐答案

您可以将其以RGB_565而不是ARGB_8888的形式读取,以将位深度从4个字节/像素减少到2个字节/像素.但是,这就是您所能做的,因为Bitmap的内存占用量是像素数乘以每个像素的位深.

You can read it in as RGB_565 instead of ARGB_8888, to reduce the bit depth from 4 bytes/pixel to 2 bytes/pixel. However, that's all you can do, as the memory footprint of a Bitmap is the number of pixels times the bit depth per pixel.

这篇关于如何减少位图内存使用量的字节数但保持其尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆