mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Catch exceptions if the file cannot be decoded.
This commit is contained in:
parent
6130a0a654
commit
5db1010e47
@ -27,12 +27,17 @@ import androidx.exifinterface.media.ExifInterface
|
|||||||
object ImageUtils {
|
object ImageUtils {
|
||||||
|
|
||||||
fun getBitmap(context: Context, uri: Uri): Bitmap? {
|
fun getBitmap(context: Context, uri: Uri): Bitmap? {
|
||||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
return try {
|
||||||
ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.contentResolver, uri))
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
} else {
|
ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.contentResolver, uri))
|
||||||
context.contentResolver.openInputStream(uri)?.use { inputStream ->
|
} else {
|
||||||
BitmapFactory.decodeStream(inputStream)
|
context.contentResolver.openInputStream(uri)?.use { inputStream ->
|
||||||
|
BitmapFactory.decodeStream(inputStream)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user