0

ビットマップがあり、最初にその中心を中心に回転させて取得した新しいビットマップを作成したいと考えています。実際にこのコードを使用していますが、機能しません。

Bitmap source = ((BitmapDrawable)r.getDrawable(R.drawable.rectangle)).getBitmap();

int targetWidth = (int)(mWidth * Math.sin(rotationAngle) + mHeight * Math.cos(rotationAngle));
int targetHeight = (int)(mWidth * Math.cos(rotationAngle) + mHeight * Math.sin(rotationAngle));

Bitmap target = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(target);
Matrix m = new Matrix();
m.setRotate(rotationAngle, targetWidth/2f, targetHeight/2f);
c.drawBitmap(source, m, null);

このコードも試しましたが、役に立ちません。

Bitmap source = ((BitmapDrawable)r.getDrawable(R.drawable.rectangle)).getBitmap();

int targetWidth = (int)(mWidth * Math.sin(rotationAngle) + mHeight * Math.cos(rotationAngle));
int targetHeight = (int)(mWidth * Math.cos(rotationAngle) + mHeight * Math.sin(rotationAngle));

Bitmap target = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(target);
c.rotate(rotationAngle, targetWidth/2f, targetHeight/2f);
c.drawBitmap(temp, 0, 0, null);

この場合、キャンバスで呼び出された回転コマンド (ただし、スケール コマンドでも同じことが起こります) は、どのパラメーターに対しても完全に無視されます。私も使用しようとしました:

c.drawColor(Color.BLACK)

それ以外の

c.drawBitmap(temp, 0, 0, null);

すべてのキャンバスをペイントすると、コマンドが無視されることが確認されます。

4

2 に答える 2

-1
int count = canvas.save();
canvas.rotate(rotationAngle, centerX, centerY);
c.drawBitmap(source, null);
canvas.restoreToCount(count);
于 2016-08-17T18:59:48.043 に答える