MAT (Eclipse Memory Analyzer) - how to view raster images from a memory dump

I am analyzing the memory usage of my Android application using the Eclipse Memory Analyzer (also known as MAT). Sometimes I can find weird instances of the android.graphics.Bitmap class using most of the heap. The problem is that I can not find the source of these bitmaps, there is no file name, no resourceID, nothing. All the information I can find for a bitmap is as follows: bitmap_info

I suppose there is an mBuffer field with an array of image pixels. But this is in some kind of internal Android format, and not in PNG.

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

+48
android bitmap eclipse-memory-analyzer memory-dump hprof
03 Oct
source share
2 answers

I found a way to view these bitmap images:

  • First you need to download and install GIMP
  • Then find your Bitmap object in MAT, right-click on the mBuffer field, select "Copy" → "Save Value to File" in the context menu and save the value of this array in any file
  • provide the .data extension to this file
  • launch GIMP, select "File" → "Open", select the .data file and click "Open"
  • The Load Image From Source Data dialog box appears. Here you need to set the correct parameters for your bitmap.
  • first select “Image Type” as “RGB Alpha” (most Android resources have this type of image, but you may need to experiment with other types of images).
  • second, set the correct width and height for your bitmap (the correct sizes can be found in the memory dump)

At this point, you should already see a preview of the original image. If you have not done so, you can try changing some other parameters in the "Load Image from Source Data" dialog box.

NOTE. To get the width and height of the image, you can look at the mWidth and mHeight in the MAT in the attributes section, as shown in the image.

+121
03 Oct
source share

You can convert memory dumps from MAT to png using ImageMagick on the command line.

In MAT for the linked Bitmap object, right-click mBuffer and select Copy → Save Value To File, specify a file with the extension .rgba .

You need to note the width and height of the bitmap from the mWidth and mHeight , which you can see in the Bitmap object.

By installing ImageMagick command-line ImageMagick (for Ubuntu apt-get install imagemagick ), you issue the convert command with the following options.

 convert -size 'width'x'height' -depth 8 filename.rgba filename.png 

for example

  convert -size 680x1209 -depth 8 phone_decor.rgba phone_decor.png 

You can check the generated png file with eog , for example eog phone_decor.rgba on Ubuntu .

+6
Sep 09 '13 at 7:08
source share



All Articles