fix: Improve error handling for image bounds decoding in MediaUtils
This commit is contained in:
@@ -51,9 +51,15 @@ object MediaUtils {
|
|||||||
|
|
||||||
val boundsOptions =
|
val boundsOptions =
|
||||||
BitmapFactory.Options().apply { inJustDecodeBounds = true }
|
BitmapFactory.Options().apply { inJustDecodeBounds = true }
|
||||||
context.contentResolver.openInputStream(uri)?.use { inputStream ->
|
val boundsStream = context.contentResolver.openInputStream(uri)
|
||||||
|
if (boundsStream == null) {
|
||||||
|
logImage("bounds stream open failed")
|
||||||
|
return@withContext null
|
||||||
|
}
|
||||||
|
boundsStream.use { inputStream ->
|
||||||
|
// decodeStream returns null when inJustDecodeBounds=true; we only need outWidth/outHeight.
|
||||||
BitmapFactory.decodeStream(inputStream, null, boundsOptions)
|
BitmapFactory.decodeStream(inputStream, null, boundsOptions)
|
||||||
} ?: return@withContext null
|
}
|
||||||
|
|
||||||
if (boundsOptions.outWidth <= 0 || boundsOptions.outHeight <= 0) {
|
if (boundsOptions.outWidth <= 0 || boundsOptions.outHeight <= 0) {
|
||||||
logImage("bounds decode failed, trying direct decode fallback")
|
logImage("bounds decode failed, trying direct decode fallback")
|
||||||
|
|||||||
Reference in New Issue
Block a user