Throw explicit exceptions when decoding images to import
This commit is contained in:
@@ -26,6 +26,7 @@ import androidx.core.util.component2
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.fairscan.app.domain.ImageLoader
|
import org.fairscan.app.domain.ImageLoader
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class AndroidImageLoader(
|
class AndroidImageLoader(
|
||||||
private val contentResolver: ContentResolver
|
private val contentResolver: ContentResolver
|
||||||
@@ -64,10 +65,13 @@ private fun decodeWithImageDecoder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun decodeWithBitmapFactory(contentResolver: ContentResolver, uri: Uri, ): Bitmap {
|
private fun decodeWithBitmapFactory(contentResolver: ContentResolver, uri: Uri, ): Bitmap {
|
||||||
val decodeOptions = BitmapFactory.Options()
|
val options = BitmapFactory.Options()
|
||||||
return contentResolver.openInputStream(uri).use {
|
val inputStream = contentResolver.openInputStream(uri)
|
||||||
BitmapFactory.decodeStream(it, null, decodeOptions)
|
?: 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 {
|
private fun computeScale(width: Int, height: Int, maxPixels: Int): Float {
|
||||||
|
|||||||
Reference in New Issue
Block a user