10

ビットマップを小さな断片に分割するための可能な方法に関する情報が必要です。

さらに重要なことは、判断するためのいくつかのオプションが必要になることです。私は多くの投稿をチェックしましたが、何をすべきかについてまだ完全には確信が持てません:

  1. ビットマップの一部を切り取る
  2. ビットマップの中間領域を切り取るにはどうすればよいですか?

これらの 2 つの投稿は、私が見つけたいくつかの良いオプションですが、各方法の CPU と RAM のコストを計算することはできません。とはいえ、やろうとしているのなら、最初から最善の方法でやらないのはどうだろう。

ビットマップ圧縮に関するいくつかのヒントとリンクを入手していただければ幸いです。2 つの方法を組み合わせることでパフォーマンスが向上する可能性があります。

4

2 に答える 2

9

この関数を使用すると、ビットマップを複数の行と列に分割できます。

例 Bitmap[][] bitmaps = splitBitmap(bmp, 2, 1); 2 次元配列に格納された垂直分割ビットマップを作成します。2列1行

例 Bitmap[][] bitmaps = splitBitmap(bmp, 2, 2); ビットマップを、2 次元配列に格納された 4 つのビットマップに分割します。2列2行

public Bitmap[][] splitBitmap(Bitmap bitmap, int xCount, int yCount) {
    // Allocate a two dimensional array to hold the individual images.
    Bitmap[][] bitmaps = new Bitmap[xCount][yCount];
    int width, height;
    // Divide the original bitmap width by the desired vertical column count
    width = bitmap.getWidth() / xCount;
    // Divide the original bitmap height by the desired horizontal row count
    height = bitmap.getHeight() / yCount;
    // Loop the array and create bitmaps for each coordinate
    for(int x = 0; x < xCount; ++x) {
        for(int y = 0; y < yCount; ++y) {
            // Create the sliced bitmap
            bitmaps[x][y] = Bitmap.createBitmap(bitmap, x * width, y * height, width, height);
        }
    }
    // Return the array
    return bitmaps;     
}
于 2014-09-20T20:42:52.387 に答える
9

ビットマップをパーツに分割したい。ビットマップから等しい部分を切り取りたいと思います。たとえば、ビットマップから 4 つの等しい部分が必要だとします。

ビットマップを4等分してビットマップの配列にする方法です。

public Bitmap[] splitBitmap(Bitmap src) {
    Bitmap[] divided = new Bitmap[4];
    imgs[0] = Bitmap.createBitmap(
        src,
        0, 0,
        src.getWidth() / 2, src.getHeight() / 2
    );
    imgs[1] = Bitmap.createBitmap(
        src,
        src.getWidth() / 2, 0,
        src.getWidth() / 2, src.getHeight() / 2
    );
    imgs[2] = Bitmap.createBitmap(
        src,
        0, src.getHeight() / 2,
        src.getWidth() / 2, src.getHeight() / 2
    );
    imgs[3] = Bitmap.createBitmap(
        src,
        src.getWidth() / 2, src.getHeight() / 2,
        src.getWidth() / 2, src.getHeight() / 2
    );
    return divided;
}
于 2013-12-24T06:46:32.483 に答える