반응형
SMALL
카메라로 찍은 이미지 파일 방향에 맞게 회전하고 리사이징 하는 코드 , bitmap으로 리턴
//path 파일 저장된 경로
fun modifyImage(path: String) : Bitmap{
val bmpFactoryOptions = BitmapFactory.Options()
var src : Bitmap
//4분의1 사이즈로 리사이징
bmpFactoryOptions.inSampleSize = 4
bmpFactoryOptions.inJustDecodeBounds = false
var bm = BitmapFactory.decodeFile(path, bmpFactoryOptions)
val exif = ExifInterface(path)
val orientString: String? = exif.getAttribute(ExifInterface.TAG_ORIENTATION)
val orientation = orientString?.toInt() ?: ExifInterface.ORIENTATION_NORMAL
var rotationAngle = 0
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) rotationAngle = 90
if (orientation == ExifInterface.ORIENTATION_ROTATE_180) rotationAngle = 180
if (orientation == ExifInterface.ORIENTATION_ROTATE_270) rotationAngle = 270
val matrix = Matrix()
matrix.setRotate(rotationAngle.toFloat(), bm.width.toFloat(), bm.height.toFloat())
src = Bitmap.createBitmap(bm, 0, 0, bm.width, bm.height, matrix, true)
return src
}
반응형
LIST
'AOS - Kotlin' 카테고리의 다른 글
[android/kotlin] handler 데이터 여러개 전달하기 (0) | 2024.04.05 |
---|---|
[android/kotlin] apk 이름 변경 (0) | 2024.03.11 |
[android/kotlin] 안드로이드 13 권한 변경 (0) | 2024.03.11 |
[android/kotlin] webview shouldOverrideUrlLoading not called (0) | 2023.06.26 |
[안드로이드] google play store 앱 내릴때 출시안됨 버튼 비활성화 (2) | 2023.05.23 |