본문 바로가기
안드로이드

안드로이드 - Bitmap(이미지) 사이즈 변경(Scale) 및 회전(Rotation)_하는 방법

by Dokon Jang 2015. 6. 24.
반응형

안드로이드에서 이미지사이즈 변경 및 회전하는 코드입니다.

 

1. 이미지 사이즈 변경(Scale)

// 가로 2배, 세로 1배인 사이즈 Matrix
Matrix matrix = new Matrix();
matrix.preScale(2.0f, 1.0f);

// 리소스의 이미지를 Bitmap으로...
Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher);
        
// 이미지 사이즈 변경
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
 

 

 

2. 이미지 회전(Rotation)

// 이미지 중심으로 90도 회전 Matrix
Matrix matrix = new Matrix();
matrix.preRotate(90, 0, 0);

// 리소스의 이미지를 Bitmap으로...
Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher);
        
// 이미지 회전
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
 

 

 

반응형

댓글