나의 플랫폼/안드로이드

[Android] Bitmap 이미지 가로 세로 회전

GsBOB 2011. 4. 4. 14:46
Bitmap 이미지를 90도 방향만큼 Rotate 시키는 함수 입니다.

가로가 세로보다 클 경우 이미지가 옆으로 눕혀서 보이는 것을 방지하기 위해 만들었습니다.
참조하세요.~

 
if(background.getHeight() < background.getWidth()){
background = imgRotate(background);
}

private Bitmap imgRotate(Bitmap bmp){
int width = bmp.getWidth(); 
int height = bmp.getHeight(); 

Matrix matrix = new Matrix(); 
matrix.postRotate(90); 

Bitmap resizedBitmap = Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true); 
bmp.recycle();

return resizedBitmap;
}