MAT(Eclipse的内存分析器) - 如何看待从内存转储位图内存、分析器、位图、如何看待

2023-09-12 03:48:44 作者:敷衍已成傷

我分析了我的Andr​​oid应用程序的内存使用情况与 Eclipse的内存分析器(也称为MAT)。有时我可以找到 android.graphics.Bitmap奇怪的实例类,利用堆的很大一部分。是什么问题,我无法找到这个位图,没有的文件名的,没有任何的 RESOURCEID 的,没有来源。所有的信息是我能找到的位图如下:

I'm analyzing memory usage of my Android app with help of Eclipse Memory Analyzer (also known as MAT). Sometimes I can find strange instances of android.graphics.Bitmap class, utilizing big portion of heap. Problem is what I can't find source of this bitmaps, no filename, no resourceID, nothing. All information what I can find for bitmap is following:

有一个字段 mBuffer 与图像的像素阵列,我假设。但它在一些内部的Andr​​oid格式,而不是PNG。

There is a field mBuffer with array of image pixels, I assume. But it's in some internal Android format, not PNG.

问题:我怎么可以查看图像再从内存中psented此位$ P $转储

Question: how can I view image represented by this bitmap from memory dump?

推荐答案

我已经找到一种方法来查看这样的位图:

I have found a way to view such bitmaps:

首先,你需要下载并安装 GIMP 接下来,找到在MAT你的位图对象,对 mBuffer 字段中单击鼠标右键,在弹出菜单中选择复制的 - >的保存值到文件的菜单项,并保存这个数组的价值的一些文件 给扩展 .DATA 该文件 在启动GIMP,选择的文件的 - >的打开的,选择 .DATA 文件,然后单击打开的按钮 的加载从原始数据图像的对话框将会出现。在这里,你需要设置正确的参数为位图 第一,选择的图像类型的作为的RGB阿尔法的(大多数Android资源有这样的图像类型,但您可能需要尝试其他类型的图像) 第二,设置正确的宽度和高度的为您的位图(正确的尺寸可以在内存转储中) First, you need to download and install GIMP Next, find your Bitmap object in MAT, right-click on mBuffer field, in the popup menu choose "Copy" -> "Save Value To File" menu item and save value of this array to some file give extension .data to that file launch GIMP, choose "File" -> "Open", select your .data file and click Open button "Load Image from Raw Data" dialog will appear. Here you need to set correct parameters for your bitmap first, choose "Image type" as "RGB Alpha" (most Android resources have this image type, but you may need to experiment with other image types) second, set correct Width and Height for your bitmap (correct dimensions can be found in the memory dump)

在这一点上,你应该已经看到原始图像的preVIEW。如果你没有,你可以尝试改变的载入图像原始数据的对话框。

At that point you should already observe preview of original image. If you didn't, you can try to change some other parameters in "Load Image from Raw Data" dialog.

注:获得一个宽的图像和高度,你可以看看 mWidth mHeight 在MAT字段属性部分如图形象的问题。

NOTE: to get a width and height of image you can look at mWidth and mHeight fields in MAT in attributes section as shown in image in question.