5

GeoTiff/PNGコードで全体を処理するには大きすぎるファイルを使用しています。

bitmapfactory でファイルの特定の領域 (たとえば、2 つの x、y 座標で指定) をデコードする可能性はありますか? 似たようなものは見つかりませんでしたhttp://developer.android.com/reference/android/graphics/BitmapFactory.html(Android の開発者リファレンス)。

ありがとう!


kcoppock のヒントで、次の解決策を設定しました。

なぜ代わりにrect初期化する必要があるのか​​ 疑問に思っていますが...Rect(left, bottom, right, top)Rect(left, top, right, bottom)

呼び出しの例:

Bitmap myBitmap = loadBitmapRegion(context, R.drawable.heightmap,
    0.08f, 0.32f, 0.13f, 0.27f);

関数:

public static Bitmap loadBitmapRegion(
    Context context, int resourceID,
    float regionLeft, float regionTop,
    float regionRight, float regionBottom) {

    // Get input stream for resource
    InputStream is = context.getResources().openRawResource(resourceID);

    // Set options
    BitmapFactory.Options opt = new BitmapFactory.Options();
    //opt.inPreferredConfig = Bitmap.Config.ARGB_8888; //standard

    // Create decoder
    BitmapRegionDecoder decoder = null;
    try {
        decoder = BitmapRegionDecoder.newInstance(is, false);
    } catch (IOException e) {
        e.printStackTrace();
    }

    // Get resource dimensions
    int h = decoder.getHeight();
    int w = decoder.getWidth();

    // Set region to decode
    Rect region = new Rect(
            Math.round(regionLeft*w), Math.round(regionBottom*h),
            Math.round(regionRight*w), Math.round(regionTop*h));

    // Return bitmap
    return decoder.decodeRegion(region, opt);

}
4

2 に答える 2

2

「特定の領域をデコードする」とはどういう意味か正確にはわかりませんが、ビットマップの特定の領域を実際に「コピー」するという意味でデコードする場合、以下に示すようにキャンバスを使用してそれを取得することができます:

        Bitmap bmpWithArea = Bitmap.createBitmap(widthDesired, heightDesired, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bmpWithArea);
        Rect area = new Rect(arealeft, areatop, arearight, areabottom);
        Rect actualSize = new Rect(0, 0, widthDesired, heightDesired);
        canvas.drawBitmap(bitmapWithAreaYouWantToGet, area, actual, paintIfAny);

        //And done, starting from this line "bmpWithArea" has the bmp that you wanted, you can assign it to ImageView and use it as regular bmp...

お役に立てれば...

よろしく!

于 2013-10-04T23:33:24.980 に答える