2017-12-27 14 views
0

ビットマップイメージの周りを回転すると、ビットマップイメージのサイズが変更され、回転が揺れて表示されます。Android、スケールなしでビットマップを自己中心に回転

public static Bitmap RotateBitmap(Bitmap source, int width, float angle) { 
     Matrix matrix = new Matrix(); 
     int px = width/2; 
     matrix.postRotate(angle, px, px); 
     Bitmap bitmap = Bitmap.createBitmap(source, 0, 0, width, width, matrix, true); 
     return bitmap; 
    } 

描画するたびにキャンバスに描画され、ビットマップの幅と高さに加えて振ることで回転します。 ビットマップを振ることなくスムーズに回転するには?

答えて

0

半分の幅を渡しているのでサイズ変更しています。これを使用してください:

public static Bitmap RotateBitmap(Bitmap source, float angle) { 
    Matrix matrix = new Matrix(); 
    matrix.postRotate(angle); 
    Bitmap bitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true); 
    return bitmap; 
} 

これは別のスレッドで呼び出す必要があります。 (AsyncTaskなど)

関連する問題