4

ImageViewを使用してビットマップをトリミングします。切り抜いたら、その切り抜いた画像を取得したいのですが、元の画像と同じになります。画像の表示可能な部分のみを取得する方法はありますか?

ImageView iv = new  ImageView(this);                        
iv.setImageBitmap(OriginalBitmap);
iv.setScaleType(ScaleType.CENTER_CROP);
Bitmap CroppedBitmap = ((BitmapDrawable) iv.getDrawable()).getBitmap();

CroppedBitmapの値はOriginalBitmapと同じです。どうすればトリミングされたものを入手できますか?

4

2 に答える 2

1

このは私にとってはうまくいきます iv.setDrawingCacheEnabled(true); Bitmap croppedBitmap = iv.getDrawingCache()

于 2015-08-24T08:31:06.537 に答える
0

画像200x200をトリミングするための次のコード

Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), 
           R.drawable.android);

    int width = bitmapOrg.width();
    int height = bitmapOrg.height();
    int newWidth = 200;
    int newHeight = 200;

    // calculate the scale - in this case = 0.4f
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;

    // createa matrix for the manipulation
    Matrix matrix = new Matrix();
    // resize the bit map
    matrix.postScale(scaleWidth, scaleHeight);

    // recreate the new Bitmap
    Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, 
                      width, height, matrix, true); 

    // make a Drawable from Bitmap to allow to set the BitMap 
    // to the ImageView, ImageButton or what ever
    BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);

    iv.setImageDrawable(bmd);
于 2012-06-07T17:16:47.710 に答える