Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 비트맵 리사이징 #142

Merged
merged 4 commits into from
Apr 19, 2024
Merged

[Feat] 비트맵 리사이징 #142

merged 4 commits into from
Apr 19, 2024

Conversation

Jokwanhee
Copy link
Member

📌 관련 이슈

📝 Work Desciption

  • S3 업로드 되는 이미지의 크기를 줄이고자 시작했습니다.
  • 비트맵 리사이징 적용 및 테스트 완료했습니다.

테스트 해본 결과

  • 3.3MB → 77.5KB 로 용량 감소
    • 약 42배 절감
  • 이미지 로드 속도 감소
    • 2s → 0.2~3s
    • 압축 포맷인 jpg 이미지를 로드할 때, 용량이 크면 느려지니 용량을 줄임으로써, 속도 개선

🔥 🔥

📚 Reference 혹은 궁금한 사항들

오랜만이네용~!

@Jokwanhee Jokwanhee added feat 구현 및 개선 Pull Request 🔥 pr 날릴때 관희 🐪  PT쌤 refactoring 리팩토링 labels Apr 18, 2024
@Jokwanhee Jokwanhee self-assigned this Apr 18, 2024
Copy link
Contributor

@l2zh l2zh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

시험기간 중 후회없는 선택...

Comment on lines +54 to +66
private fun rotateBitmap(orientation: Int, bitmap: Bitmap?): Bitmap? = when (orientation) {
ExifInterface.ORIENTATION_ROTATE_90 -> rotateImage(bitmap, 90f)
ExifInterface.ORIENTATION_ROTATE_180 -> rotateImage(bitmap, 180f)
ExifInterface.ORIENTATION_ROTATE_270 -> rotateImage(bitmap, 270f)
else -> bitmap
}

private fun rotateImage(bitmap: Bitmap?, angle: Float): Bitmap? {
val matrix = Matrix().apply { postRotate(angle) }
return bitmap?.let {
Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이미지 회전은 왜 필요한건가욤??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

글고 궁금한게 리사이징 해도 이미지 해상도는 크게 변화 없나요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l2zh

이미지 회전은 왜 필요한건가욤??

이유는 단순합니다. 카메라로 사진 촬영 시, 기기내부 센서의 방향에 사진이 저장되는데 해당 사진 URI를 비트맵으로 전환하는 내부 메타데이터로 회전된 뱡향이 적용된 사진이 보여지게 됩니다.
그냥 똑바로 안찍어서 회전되어보입니다..ㅋㅋ
(ImageDecoder를 사용하면 상관없지만, BitmapFactory를 사용할 때 생기는 이슈입니다.)

글고 궁금한게 리사이징 해도 이미지 해상도는 크게 변화 없나요?

이미지의 해상도는 낮아질 것 같습니다. 하지만 크게 변화가 없다고 생각합니다. 이유는 압축 파일의 File Extension 을 JPEG로 사용하였기에 한 번의 압축은 이미지의 품질 저하를 많이 일으키지 않습니다.
하지만 이미지를 로드할 때, 큰 ImageView 에 작은 용량 사진을 넣으면 품질 저하가 나타날지도..? 라는 생각인데 요건 테스트를 진행해보려고 합니당.
(당연한 이야기 같기도..)
일단 제가 크게 파일의 용량을 줄인 이유는 우리가 진행하는 서비스의 사진은 작게 보이기 때문입니다! 🐬

이준희 시험 화이팅~ 🔥 🔥

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l2zh
추가적으로 테스트해봤습니다.
기본적인 사진촬영과 카메라 사진은 1~3MB 합니다. 이에 대한 위 로직은 사진읜 품질저하를 일으키지 않습니다. 해상도를 1/4 비율로 낮추긴했지만, 크게 품질저하를 느끼지 못했습니다.

하지만 스크린샷이나 어디서 가져온 캡처본은 크기가 작습니다.
테스트한 123KB 캡처본으로 한 결과, 우리 서비스에서는 드라마틱한 품질 저하를 볼 수 없긴 합니다만 품질 저하는 확실히 있습니다.

BitmapFactory.Options().apply { 
  inSampleSize = 4 
}

// 변경한 부분
inSampleSize = 2

로 하면서 해상도의 비율을 1/4 로 줄였지만, 1/2로 줄여도 괜찮을 것 같아 수정했습니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 그렇군요! 감사합니다~
형도 시험 화이팅...ㅎㅎ

@Jokwanhee Jokwanhee merged commit 65aeccd into develop Apr 19, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat 구현 및 개선 Pull Request 🔥 pr 날릴때 refactoring 리팩토링 관희 🐪  PT쌤
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants