2

画面サイズよりも大きなビットマップがあるこのプロジェクトがあります。画面にぴったり合うようにサイズを変更したい。タイトルバーがなく、フルスクリーン モードです。これは私の非動作コードです:

public class ScopView extends View
{
    private Scop thescop;

    public ScopView(Context context, Scop newscop)
    {
        super(context);
        this.thescop = newscop;
    }

    @Override
    public void onDraw(Canvas canvas)
    {
        Bitmap scopeBitmap;
        BitmapFactory.Options bfOptions = new BitmapFactory.Options();
        bfOptions.inDither = false;
        bfOptions.inPurgeable = true;
        bfOptions.inInputShareable = true;
        bfOptions.inTempStorage = new byte[32 * 1024];

        scopeBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.scope, bfOptions);
        scopeBitmap.createScaledBitmap(scopeBitmap, SniperActivity.Width, SniperActivity.Height, false);
        canvas.drawBitmap(scopeBitmap, SniperActivity.scopx, SniperActivity.scopy, null);
    }
}

ここでは createScaledBitmap メソッドを使用していますが、それ自体をソースとして使用し、アクティビティのいくつかの変数を使用して、画面の設定からウィンドウの高さと幅を取得しています。

4

3 に答える 3

11

以下のコードを使用して、ビットマップのサイズを変更できます。

int h = 320; // Height in pixels
int w = 480; // Width in pixels    
Bitmap scaled = Bitmap.createScaledBitmap(largeBitmap, h, w, true);
于 2012-04-21T09:21:08.163 に答える
1

また、以下のコード スニペットを使用することもできます。

public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;

    // Create a matrix for the manipulation
    Matrix matrix = new Matrix();

    // Resize the bit map
    matrix.postScale(scaleWidth, scaleHeight);

    // Recreate the new Bitmap
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);

    return resizedBitmap;
}
于 2012-04-21T09:22:22.623 に答える
1

このコードは、これを試すのに役立ちます

int REQ_WIDTH = 0;
int REQ_HEIGHT = 0;
REQ_WIDTH =imageView.getWidth();
vREQ_HEIGHT =imageView.getHeight();
mImageView.setImageBitmap(Bitmap.createScaledBitmap(BitmapFactory.decodeFile(imageURI, options), REQ_HEIGHT, REQ_WIDTH, true));
于 2013-04-04T15:19:32.037 に答える