2015-01-22 6 views
1

Bitmap 회전에 이상한 문제가 있습니다. 내 코드의 그 :안드로이드 매트릭스 비트 맵 변경 센터의 회전

Bitmap 회전 반환 내 방법입니다 그

int cx_gear_big = (getWidth() - gear_big.getWidth()) >> 1; 
int cy_gears_big = (getHeight() - gear_big.getHeight()) >> 1; 
canvas.drawBitmap(rotateGear(gear_big, bigGearAngle), cx_gear_big,cy_gears_big, null); 

방법 onDraw에서 :

public static Bitmap rotateGear(Bitmap source, int angle) 
    { 
     Matrix matrix = new Matrix(); 
     matrix.postRotate(angle); 
     return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true); 

    } 

canvas에서 몇 기어를 가지고 있지만, 정말 중요하지 않습니다.

내 문제 : 다음 다시 온다가 아래로 이동하고 왼쪽

Bitmap (기어)를 회전하고있어 (이 회전 각도에 따라 다름) ... 내 문제는 어디에서 할 수 있습니다 이 경우에는?

UPD : Bitmap의 번역은 선형이 아닙니다. 튀는 것과 같습니다.

+1

시도'사용 setRotate()'대신') postRotate ('의 : http://developer.android.com/reference/android/graphics/Matrix.html#setRotate%28float%29 –

+0

작동하지 않는다 동일한 문제 –

+1

자세한 특정 지점 지점 주위를 회전하십시오. setRotate (float degrees, float px, float py) 지정된 각도로 회전하도록 행렬을 설정하고 피벗 점을 (px, py)로 설정합니다. 0,0은 이미지의 왼쪽 상단이므로 px, py는 너비/2, 높이/2입니다. – danny117

답변

1

이 문제를 해결하는 가장 이상적인 방법은 회전하기 전에 행렬을 변환하고 다시 변환하는 것입니다. 코드 예제 :

Matrix m = new Matrix(); 
float px = getWidth()/2; 
float py = getHeight()/2; 
m.postTranslate(-bitmap.getWidth()/2, -bitmap.getHeight()/2); 
m.postRotate(angle); 
m.postTranslate(px, py); 
canvas.drawBitmap(bitmap, m, null);