diff --git a/app/src/main/java/com/rosetta/messenger/utils/MediaUtils.kt b/app/src/main/java/com/rosetta/messenger/utils/MediaUtils.kt index 402c675..fc36f51 100644 --- a/app/src/main/java/com/rosetta/messenger/utils/MediaUtils.kt +++ b/app/src/main/java/com/rosetta/messenger/utils/MediaUtils.kt @@ -51,9 +51,15 @@ object MediaUtils { val boundsOptions = 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) - } ?: return@withContext null + } if (boundsOptions.outWidth <= 0 || boundsOptions.outHeight <= 0) { logImage("bounds decode failed, trying direct decode fallback")