Throw explicit exceptions when decoding images to import

This commit is contained in:
Pierre-Yves Nicolas
2026-04-10 07:35:22 +02:00
parent 31155275e8
commit 479680a83d

View File

@@ -26,6 +26,7 @@ import androidx.core.util.component2
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.fairscan.app.domain.ImageLoader
import java.io.IOException
class AndroidImageLoader(
private val contentResolver: ContentResolver
@@ -64,10 +65,13 @@ private fun decodeWithImageDecoder(
}
private fun decodeWithBitmapFactory(contentResolver: ContentResolver, uri: Uri, ): Bitmap {
val decodeOptions = BitmapFactory.Options()
return contentResolver.openInputStream(uri).use {
BitmapFactory.decodeStream(it, null, decodeOptions)
}!!
val options = BitmapFactory.Options()
val inputStream = contentResolver.openInputStream(uri)
?: throw IOException("Cannot open input stream for uri: $uri")
return inputStream.use {
BitmapFactory.decodeStream(it, null, options)
?: throw IOException("Failed to decode bitmap for uri: $uri")
}
}
private fun computeScale(width: Int, height: Int, maxPixels: Int): Float {