1

大きなビットマップを処理する Android アプリを作成しており、ビットマップを個別の「タイル」に分割し、各タイルを個別に処理してから、最終的なビットマップに貼り付ける必要があります。

これを行う方法の手がかりはありますか?createBitmap() を使用して、いくつかのネストされた for ループで小さなタイルを指定するのは簡単だと思っていましたが、setPixels が思ったように機能しないため、思ったほど簡単ではありません。

私が持っている複雑さは、処理がビットマップの側面の周りにいくつかの余分なピクセルを確認する必要があるため、「タイル」がより大きなビットマップの端にない場所でオーバーラップする必要があることです。画像の端に黒いピクセルのレイヤーをいくつか追加するだけで画像を分割する必要がない場合は、これを回避しますが、タイルでは実際の周囲のピクセルの情報が必要なため、これは機能しません。処理がうまくいきません。

これを行う簡単な方法はありますか?そうでない場合、setPixels と createBitmap を使用してどうすればよいですか?

これまでの私のコード:

        Bitmap finalImg = Bitmap.createBitmap(sourceImage.getWidth(), sourceImage.getHeight(), Bitmap.Config.ARGB_8888);  //Bitmap to store the final, processed image
        Bitmap tile = null;  //Temporary Bitmap to store tiles

        int tileDiameter = 500;  //Width and height of tiles
        int borderWidth = 5;  //Amount of pixel overlap from other tiles

        for (int y = 0 ; y < sourceImage.getHeight() ; y += tileDiameter) {
            for (int x = 0 ; x < sourceImage.getWidth() ; x += tileDiameter) {
                if (x == 0) {
                    if (y == 0) {
                        tile = Bitmap.createBitmap(sourceImage, x, y, (tileDiameter + borderWidth), (tileDiameter + borderWidth));
                    }
                    else {
                        tile = Bitmap.createBitmap(sourceImage, x, (y - borderWidth), (tileDiameter + borderWidth), (tileDiameter + borderWidth));
                    }
                }
                else {
                    if (y == 0) {
                        tile = Bitmap.createBitmap(sourceImage, (x - borderWidth), y, (tileDiameter + borderWidth), (tileDiameter + borderWidth));
                    }
                    else {
                        tile = Bitmap.createBitmap(sourceImage, (x - borderWidth), (y - borderWidth), (tileDiameter + borderWidth), (tileDiameter + borderWidth));
                    }
                }
                processor.process(tile);
                //I need to attach this (processed) tile to it's correct location in finalImg. How!??
            }
        }
4

1 に答える 1