@@ -11,13 +11,16 @@ import androidx.activity.result.PickVisualMediaRequest
1111import androidx.activity.result.contract.ActivityResultContracts
1212import androidx.appcompat.app.AppCompatActivity
1313import androidx.lifecycle.lifecycleScope
14+ import io.scanbot.common.getOrNull
15+ import io.scanbot.common.getOrThrow
1416import io.scanbot.example.MRZResultActivity.Companion.newIntent
1517import io.scanbot.example.common.Const
1618import io.scanbot.example.common.applyEdgeToEdge
1719import io.scanbot.example.common.showToast
1820import io.scanbot.example.databinding.ActivityMrzStillImageScanningBinding
1921import io.scanbot.sdk.ScanbotSDK
2022import io.scanbot.sdk.docprocessing.Page
23+ import io.scanbot.sdk.image.ImageRef
2124import io.scanbot.sdk.ui_v2.common.activity.registerForActivityResultOk
2225import io.scanbot.sdk.ui_v2.document.DocumentScannerActivity
2326import io.scanbot.sdk.ui_v2.document.configuration.DocumentScanningFlow
@@ -30,7 +33,7 @@ class MrzStillImageScanningActivity : AppCompatActivity() {
3033
3134 private val binding by lazy { ActivityMrzStillImageScanningBinding .inflate(layoutInflater) }
3235 private val scanbotSdk by lazy { ScanbotSDK (this ) }
33- private val mrzScanner by lazy { scanbotSdk.createMrzScanner().apply {
36+ private val mrzScanner by lazy { scanbotSdk.createMrzScanner().getOrThrow(). apply {
3437 setConfiguration(this .copyCurrentConfiguration().apply {
3538 // frame accumulation is not needed for still image scanning
3639 this .frameAccumulationConfiguration.minimumNumberOfRequiredFramesWithEqualScanningResult = 1
@@ -103,7 +106,7 @@ class MrzStillImageScanningActivity : AppCompatActivity() {
103106 }
104107
105108 private suspend fun scanMrz (page : Page ) {
106- val result = mrzScanner.scanFromBitmap (page.documentImage, 0 )
109+ val result = mrzScanner.run (page.documentImageRef !! ).getOrNull( )
107110
108111 withContext(Dispatchers .Main ) {
109112 binding.progressBar.visibility = View .GONE
@@ -120,14 +123,15 @@ class MrzStillImageScanningActivity : AppCompatActivity() {
120123
121124 private suspend fun importImageToPage (uri : Uri ) {
122125 val page = withContext(Dispatchers .Default ) {
123- val inputStream = contentResolver.openInputStream(uri)
124- val bitmap = BitmapFactory .decodeStream (inputStream)
126+ val inputStream = contentResolver.openInputStream(uri) ? : throw IllegalStateException ( " Cannot open input stream from URI: $uri " )
127+ val image = ImageRef .fromInputStream (inputStream)
125128
126129 val document = scanbotSdk.documentApi.createDocument()
127- val page = document.addPage(bitmap )
130+ val page = document.addPage(image )
128131
132+ val documentScanner = scanbotSdk.createDocumentScanner().getOrThrow()
129133 val contourResult =
130- scanbotSdk.createDocumentScanner().scanFromBitmap(bitmap )?.pointsNormalized ? : kotlin.run {
134+ documentScanner. run (image).getOrNull( )?.pointsNormalized ? : kotlin.run {
131135 Log .e(Const .LOG_TAG , " Error finding document on page " + page.uuid)
132136 PolygonHelper .getFullPolygon()
133137 }
0 commit comments