对我的应用程序进行剥皮会消耗本机堆中的大量 Mb(比图像实际大小多得多)
我在我的应用程序中使用皮肤,并在某些活动中加载 1.5 Mb 的图像。 这应该不是问题.... 1.5 Mb + 应用程序加载时默认约为 6Mb...但是,情况完全不同。 我在布局 xml 中作为可绘制对象加载的每个 png,都从其实际大小至少乘以 10....,我编写了一个示例应用程序,除了黑屏之外什么都没有,并加载了一次,上面没有任何内容,获得了 5.8Mb 的本机堆,然后加载了一个 25Kb 的小 png,你猜怎么着...... 6.25Mb。 我加载我的应用程序时只加载了皮肤,它的大小从 14.5Mb 开始!!!!!!!!!
所以现在我正在每次活动更改后进行位图回收操作。
这是 Android 的已知问题吗? png 文件在本机堆中加载的大小要大得多? 除了我目前的计划之外还有其他解决方案吗?
谢谢。
I use a skin in my app,and load something like 1.5 Mb of images at some of the activities.
This shouldn't be a problem.... 1.5 Mb + default of ~6Mb for the app when loaded... however, things are quite different.
each png I load as a drawable in my layout xmls, is being multiplied by at least 10 from its actual size...., I wrote a sample app with nothing except for a black screen, and loaded it once without anything on it and got native-heap of 5.8Mb, and then loaded it with a small png of 25Kb and guess what.... 6.25Mb.
I loaded my application with nothing but the skin, and it started with 14.5Mb!!!!!!!!
so now I am in the middle of doing a bitmap recycle operation after each and every activity change.
Is this a known issue with android?
png files are loaded with much bigger size inside the native-heap?
is there a solution other than my current plan?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PNG 文件(以及许多其他图像格式,例如 JPEG)是压缩文件,与 zip 文件非常相似。当您将它们加载到内存中时,它们将被解压缩
并因此占用更多空间。
多少取决于内部图像配置,默认为< code>ARGB8888,每个像素占用 4 个字节。因此,内存消耗仅取决于图像大小,而不取决于磁盘上的文件大小(文件大小可能会变得非常小。例如:由一种颜色组成的 500x500 像素位图具有良好的压缩比)。
500x500 像素图像的示例为
500*500*4 字节 = 0.954 MB
,几乎是 1 MB。PNG files (as well as many other image formats, such as JPEG) are compressed files, pretty much similar to zip-files. When you load them into memory they will be uncompressed
and take more space consequently.
How much depends on the internal image config, the default is
ARGB8888
, which takes 4 bytes per pixel. So the memory consumption only depends on the image size, not on the filesize on disk (which can get pretty small. For example: A 500x500 px bitmap consisting of one color has a good compression ratio).Example for a 500x500 px image is
500*500*4 bytes = 0.954 MB
, which is almost one megabyte.