반응형
- 구현 코드
registerForActivityResult(ActivityResultContracts.GetContent()) {
it?.let { binding.ivPost.setImageURI(it) }
}
- 상황
1. Android registerForActivityResult 을 이용하여 사진 선택
2. 구현 코드를 통해 ImageView에 표시 -- Error --
- 에러 내용 간략화 ( 접은글 상세 )
android.graphics.ImageDecoder$DecodeException: Input was incomplete
더보기
Unable to open content: content://media/picker/0/com.android.providers.media.photopicker/media/1000002221
android.graphics.ImageDecoder$DecodeException: Input was incomplete.
at android.graphics.ImageDecoder.onPartialImage(ImageDecoder.java:2135)
at android.graphics.ImageDecoder.nDecodeBitmap(Native Method)
at android.graphics.ImageDecoder.decodeBitmapInternal(ImageDecoder.java:1865)
at android.graphics.ImageDecoder.decodeDrawableImpl(ImageDecoder.java:1948)
at android.graphics.ImageDecoder.decodeDrawable(ImageDecoder.java:1904)
at android.widget.ImageView.getDrawableFromUri(ImageView.java:1019)
at android.widget.ImageView.resolveUri(ImageView.java:988)
at android.widget.ImageView.setImageURI(ImageView.java:562)
at androidx.appcompat.widget.AppCompatImageView.setImageURI(AppCompatImageView.java:132)
at com.example.패키지.view.에러파일.galleryResult$lambda$4(에러파일.kt:57)
at com.example.패키지.view.에러파일.$r8$lambda$dwzKcIPZS7a8_GaD_jOmKHhTM1k(Unknown Source:0)
at com.example.패키지.view.에러파일$$ExternalSyntheticLambda10.onActivityResult(Unknown Source:4)
at androidx.activity.result.ActivityResultRegistry.doDispatch(ActivityResultRegistry.java:414)
at androidx.activity.result.ActivityResultRegistry.dispatchResult(ActivityResultRegistry.java:371)
at androidx.activity.ComponentActivity.onActivityResult(ComponentActivity.java:845)
at androidx.fragment.app.FragmentActivity.onActivityResult(FragmentActivity.java:151)
at android.app.Activity.dispatchActivityResult(Activity.java:8951)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5987)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:6033)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67)
at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8762)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
resolveUri failed on bad bitmap uri: content://media/picker/0/com.android.providers.media.photopicker/media/1000002221
- 해결
contextResolver 를 통해 inputStream 을 생성하여 bitmap decode 실행
val stream = contentResolver.openInputStream(uri)
val bitmap = BitmapFactory.decodeStream(stream)
binding.ivPost.setImageBitmap(bitmap)
반응형
'오류 해결' 카테고리의 다른 글
[Android] MPAndroidChart Could not find com.github.PhilJay:MPAndroidChart:v3.1.0 해결 (0) | 2024.03.26 |
---|---|
[Android] Room Bitmap 사용하기 - Canvas: trying to draw too large bitmap Error (0) | 2023.12.11 |