Programing/android
[android studio] image 회전시키기, bitmap 이미지 회전
Benedictus711
2021. 10. 24. 16:56
728x90
아래 메서드를 이용하여 이미지를 회전 시킬 수 있다.
// 이미지 회전 함수
public Bitmap rotateImage(Bitmap src, float degree) {
// Matrix 객체 생성
Matrix matrix = new Matrix();
// 회전 각도 셋팅
matrix.postRotate(degree);
// 이미지와 Matrix 를 셋팅해서 Bitmap 객체 생성
return Bitmap.createBitmap(src, 0, 0, src.getWidth(),
src.getHeight(), matrix, true);
}
drawable을 bitmap으로 변환시킨 뒤 회전처리를 할 수도 있고,
imageView의 이미지를 아래와 같이 BitmapDrawable로 변환시킨 뒤 bitmap으로 받아
이미지를 회전 시킬 수 있다
BitmapDrawable drawable = (BitmapDrawable)imageView.getDrawable();
Bitmap bitmap = drawable.getBitmap();
728x90