对我的应用程序进行剥皮会消耗本机堆中的大量 Mb(比图像实际大小多得多)

发布于 2024-12-09 23:21:28 字数 392 浏览 3 评论 0原文

我在我的应用程序中使用皮肤,并在某些活动中加载 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

埖埖迣鎅 2024-12-16 23:21:28

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文