MAT (Eclipse Memory Analyzer) - how to view bitmaps from memory dump
Asked Answered
P

2

49

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: bitmap_info

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

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

Pome answered 3/10, 2012 at 13:32 Comment(4)
If mBuffer is null, how can check the value of this member variable of a Bitmap in code?Breughel
how did you show the variables values of the bitmap?Selfevident
hi mate. I can't find similar window with the information about bitmap in my MAT Eclipse. Where did you find it?Hemmer
@Hemmer It is Inspector.Tips
P
124

I have found a way to view such bitmaps:

  • 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)

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.

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.

Pome answered 3/10, 2012 at 13:32 Comment(10)
This should be upvoted more. This is the most useful thing an Android developer would want. Brilliant!Underwriter
For me, mBuffer copy only values, not bytes. 'Copy' works on byte[xxxxx] . Also, to be clear: width X height its spec of tablet. For exemple: I tested this operation on amazon hd8,9 and I have 1200x1920 .Contextual
Edit: it was background image, that why height of tablet was same. For me, its not clear where I can find width and of height of selected byte arrayContextual
I have the same question as Sergey: how to know the width and height of the selected img?Etheridge
As you can see at first image in the post - there are two fields mWidth and mHeightPome
in eclipse mat where is mBuffer field.plz anybody tell me.Shepard
its in the attributes tab in the Inspector Window. Window>InspectorStepmother
is it possible to open the raw data via the "paint.net" app instead of GIMP ? also, as others have asked, how do you get the width and height of the image?Selfevident
How did they get the window which specifies the mHeight and mWidth in the question? I couldn't get it in MAT.Cabal
For those who can't find the window showing mWidth-mHeight, Goto Window->Show View->MAT->Inspector. Select an object in dominator tree and in the inspector window you can see the height-width.Bookerbookie
A
6

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

In MAT for related Bitmap object right click mBuffer field and select "Copy" -> "Save Value To File", name the file with an .rgba extension.

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

Having ImageMagick command line tools installed (for Ubuntu apt-get install imagemagick), you issue convert command with the following parameters.

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 generated png file via eog, like eog phone_decor.rgba on Ubuntu easily.

Arezzini answered 9/9, 2013 at 7:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.