7

アプリの重大なメモリの問題を追跡する過程で、アプリからいくつかのヒープ ダンプを調べましたが、ほとんどの場合、知らない巨大なビットマップがあります。

9.4MB、または 9,830,400 バイト、または実際にはピクセルあたり 4 バイトの 1280x1920 の画像が必要です。

私はEclipse MATをチェックインしました。それは実際にはバイト[98​​30400]であり、android.graphics.Bitmap.

これをファイルにダンプして確認したいと思います。どこから来ているのか理解できません。すべてのドローアブルの中で最大の画像は 640x960 の png で、3MB もかかりません。

Eclipseを使用して「値をファイルにコピー」しようとしましたが、バッファをファイルに出力するだけだと思います.バイトストリームを読み取ってピクセルあたり4バイトとして表示できる画像ソフトウェアはわかりません画像。

何か案が?

私が試したことは次のとおりです。バイト配列をファイルにダンプし、/sdcard/img にプッシュし、次のようなアクティビティをロードします。

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
        final File inputFile = new File("/sdcard/img");
        final FileInputStream isr = new FileInputStream(inputFile);
        final Bitmap bmp = BitmapFactory.decodeStream(isr);
        ImageView iv = new ImageView(this);
        iv.setImageBitmap(bmp);
        setContentView(iv);
        Log.d("ImageTest", "Image was inflated");
    } catch (final FileNotFoundException e) {
        Log.d("ImageTest", "Image was not inflated");
    }
}

何も見えませんでした。

画像がどのようにエンコードされているか知っていますか?に格納されているとしbyte[] bufferます。buffer[0]buffer[1]ですか、緑ですか?

4

5 に答える 5

3

簡単な答えについては、こちらを参照してください: MAT (Eclipse Memory Analyzer) - メモリ ダンプからビットマップを表示する方法

TL;DR - GIMP をインストールし、生の RGB アルファとして画像を読み込みます

于 2013-01-31T18:14:16.020 に答える
2

OK -- 試行錯誤の末、ようやくこのバイト配列から何かを得ることができました。この単純な C プログラムを作成して、バイト配列を Windows ビットマップ ファイルに変換しました。誰かが興味を持っている場合に備えて、コードを削除しています。
これを VisualC 6.0 および gcc 3.4.4 に対してコンパイルしました。どの OS でも動作するはずです (Windows、Linux、および MacOS X でテスト済み)。

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

/* Types */
typedef unsigned char byte;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef int int32_t;

/* Constants */
#define RMASK 0x00ff0000
#define GMASK 0x0000ff00
#define BMASK 0x000000ff
#define AMASK 0xff000000

/* Structures */
struct bmpfile_magic {
  unsigned char magic[2];
};

struct bmpfile_header {
  uint32_t filesz;
  uint16_t creator1;
  uint16_t creator2;
  uint32_t bmp_offset;
};

struct bmpfile_dibheader {
  uint32_t header_sz;
  uint32_t width;
  uint32_t height;
  uint16_t nplanes;
  uint16_t bitspp;
  uint32_t compress_type;
  uint32_t bmp_bytesz;
  int32_t hres;
  int32_t vres;
  uint32_t ncolors;
  uint32_t nimpcolors;

  uint32_t rmask, gmask, bmask, amask;
  uint32_t colorspace_type;
  byte colorspace[0x24];
  uint32_t rgamma, ggamma, bgamma;
};

/* Displays usage info and exits */
void usage(char *cmd) {
    printf("Usage:\t%s <img_src> <img_dest.bmp> <width> <height>\n"
        "\timg_src:\timage byte buffer obtained from Eclipse MAT, using 'copy > save value to file' while selecting the byte[] buffer corresponding to an android.graphics.Bitmap\n"
        "\timg_dest:\tpath to target *.bmp file\n"
        "\twidth:\t\tpicture width, obtained in Eclipse MAT, selecting the android.graphics.Bitmap object and seeing the object member values\n"
        "\theight:\t\tpicture height\n\n", cmd);
    exit(1);
}

/* C entry point */
int main(int argc, char **argv) {
    FILE *in, *out;
    char *file_in, *file_out;
    int w, h, W, H;
    byte r, g, b, a, *image;
    struct bmpfile_magic magic;
    struct bmpfile_header header;
    struct bmpfile_dibheader dibheader;

    /* Parse command line */
    if (argc < 5) {
        usage(argv[0]);
    }
    file_in = argv[1];
    file_out = argv[2];
    W = atoi(argv[3]);
    H = atoi(argv[4]);
    in = fopen(file_in, "rb");
    out = fopen(file_out, "wb");

    /* Check parameters */
    if (in == NULL || out == NULL || W == 0 || H == 0) {
        usage(argv[0]);
    }

    /* Init BMP headers */
    magic.magic[0] = 'B';
    magic.magic[1] = 'M';

    header.filesz = W * H * 4 + sizeof(magic) + sizeof(header) + sizeof(dibheader);
    header.creator1 = 0;
    header.creator2 = 0;
    header.bmp_offset = sizeof(magic) + sizeof(header) + sizeof(dibheader);

    dibheader.header_sz = sizeof(dibheader);
    dibheader.width = W;
    dibheader.height = H;
    dibheader.nplanes = 1;
    dibheader.bitspp = 32;
    dibheader.compress_type = 3;
    dibheader.bmp_bytesz = W * H * 4;
    dibheader.hres = 2835;
    dibheader.vres = 2835;
    dibheader.ncolors = 0;
    dibheader.nimpcolors = 0;
    dibheader.rmask = RMASK;
    dibheader.gmask = BMASK;
    dibheader.bmask = GMASK;
    dibheader.amask = AMASK;
    dibheader.colorspace_type = 0x57696e20;
    memset(&dibheader.colorspace, 0, sizeof(dibheader.colorspace));
    dibheader.rgamma = dibheader.bgamma = dibheader.ggamma = 0;

    /* Read picture data */
    image = (byte*) malloc(4*W*H);
    if (image == NULL) {
        printf("Could not allocate a %d-byte buffer.\n", 4*W*H);
        exit(1);
    }
    fread(image, 4*W*H, sizeof(byte), in);
    fclose(in);

    /* Write header */
    fwrite(&magic, sizeof(magic), 1, out);
    fwrite(&header, sizeof(header), 1, out);
    fwrite(&dibheader, sizeof(dibheader), 1, out);

    /* Convert the byte array to BMP format */
    for (h = H-1; h >= 0; h--) {
        for (w = 0; w < W; w++) {
            r = *(image + w*4 + 4 * W * h);
            b = *(image + w*4 + 4 * W * h + 1);
            g = *(image + w*4 + 4 * W * h + 2);
            a = *(image + w*4 + 4 * W * h + 3);

            fwrite(&b, 1, 1, out);
            fwrite(&g, 1, 1, out);
            fwrite(&r, 1, 1, out);
            fwrite(&a, 1, 1, out);
        }
    }

    free(image);
    fclose(out);
}

このツールを使用して、この 1280x1920 ビットマップの生成に使用された画像を認識することができました。

于 2012-03-08T15:16:32.060 に答える
2

Android Studio の最新バージョン (執筆時点では 2.2.2) から、ビットマップ ファイルを直接表示できることがわかりました。

  1. [Android モニター] タブ (左下) を開き、[メモリ] タブを開きます。
  2. 「Javaヒープのダンプ」ボタンを押します

  3. 現在のスナップショットの「ビットマップ」クラス名を選択し、ビットマップの各インスタンスを選択して、どのイメージが予想より多くのメモリを正確に消費しているかを確認します。(画面 4 と 5)

  4. クラス名を選択してくださいBitmap…</p>

ここに画像の説明を入力

  1. ビットマップの各インスタンスを選択

ここに画像の説明を入力

それを右クリックして、選択しますView Bitmap

ここに画像の説明を入力

于 2016-12-03T07:55:24.833 に答える
0

USB 接続を有効にして、ファイルを別のコンピューターにコピーし、調査するツールを追加することができます。

一部のデバイスは、スタート ボタンが押されたときに現在の画面をファイル システムにダンプするように構成できます。多分これはあなたに起こります。

于 2012-03-08T16:02:15.767 に答える
0

画像への入力を取得し、fileinput ストリーム/データストリームを使用してビットマップ オブジェクトに変換するだけです。また、使用される各イメージのデータを表示するためのログを追加します。

于 2012-03-08T01:11:45.123 に答える