-
(Android)앨범에서 이미지 가져올때 회전되는 문제 수정 하는방법Programing Language/Android Studio(Java&Kotlin) 2019. 6. 4. 15:56728x90반응형This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
ExifInterface exif = null; try { exif = new ExifInterface(path); // path 파일 uri } catch (IOException e) { e.printStackTrace(); } int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); Bitmap bmRotated = rotateBitmap(bitmap, orientation); //bitmap 사진 파일(bitmap형태의) /* 17번째 코드에 사용될 메서드 */ public static Bitmap rotateBitmap(Bitmap bitmap, int orientation) { Matrix matrix = new Matrix(); switch (orientation) { case ExifInterface.ORIENTATION_NORMAL: return bitmap; case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: matrix.setScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_180: matrix.setRotate(180); break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: matrix.setRotate(180); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_TRANSPOSE: matrix.setRotate(90); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_90: matrix.setRotate(90); break; case ExifInterface.ORIENTATION_TRANSVERSE: matrix.setRotate(-90); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_270: matrix.setRotate(-90); break; default: return bitmap; } try { Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); bitmap.recycle(); return bmRotated; } catch (OutOfMemoryError e) { e.printStackTrace(); return null; } } 728x90반응형'Programing Language > Android Studio(Java&Kotlin)' 카테고리의 다른 글
[Android Studio] 인스타같은 이미지 필터 예제 (0) 2019.08.29 [Android]바코드 or QR코드 읽기 (0) 2019.08.26 자바 for문을 이용하여 Map, Hash 값 꺼내기 (0) 2019.08.23 AlterDialog 코드 (0) 2019.08.13 Android)Bottom navigationbar 코딩으로 선택하기 (0) 2019.05.31