diff --git a/documentscanner/src/main/java/com/websitebeaver/documentscanner/utils/ImageUtil.kt b/documentscanner/src/main/java/com/websitebeaver/documentscanner/utils/ImageUtil.kt index b3cc247..0478169 100644 --- a/documentscanner/src/main/java/com/websitebeaver/documentscanner/utils/ImageUtil.kt +++ b/documentscanner/src/main/java/com/websitebeaver/documentscanner/utils/ImageUtil.kt @@ -51,7 +51,14 @@ class ImageUtil { } // try reading image without OpenCV - var imageBitmap = BitmapFactory.decodeFile(filePath) + var imageBitmap: Bitmap + try { + imageBitmap = BitmapFactory.decodeFile(filePath) + } catch (e: OutOfMemoryError) { + var options = BitmapFactory.Options(); + options.inSampleSize = 2; + imageBitmap = BitmapFactory.decodeFile(filePath, options); + } val rotation = when (ExifInterface(filePath).getAttributeInt( ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL @@ -165,4 +172,4 @@ class ImageUtil { contentResolver.openInputStream(Uri.parse(fileUriString)) ) } -} \ No newline at end of file +}