画面サイズよりも大きなビットマップがあるこのプロジェクトがあります。画面にぴったり合うようにサイズを変更したい。タイトルバーがなく、フルスクリーン モードです。これは私の非動作コードです:
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 メソッドを使用していますが、それ自体をソースとして使用し、アクティビティのいくつかの変数を使用して、画面の設定からウィンドウの高さと幅を取得しています。