@@ -33,10 +33,12 @@ import io.scanbot.sdk.document.DocumentScannerFrameHandler
3333import io.scanbot.sdk.documentscanner.DocumentDetectionStatus
3434import io.scanbot.sdk.documentscanner.DocumentScanner
3535import io.scanbot.sdk.image.ImageRef
36+ import io.scanbot.sdk.imageprocessing.ScanbotSdkImageProcessor
3637import io.scanbot.sdk.process.ImageProcessor
3738import io.scanbot.sdk.ui.PolygonView
3839import io.scanbot.sdk.ui.camera.ScanbotCameraXView
3940import io.scanbot.sdk.ui.camera.ShutterButton
41+ import io.scanbot.sdk.util.PolygonHelper
4042
4143class MainActivity : AppCompatActivity (), DocumentScannerFrameHandler.ResultHandler {
4244 private lateinit var cameraView: ScanbotCameraXView
@@ -223,16 +225,14 @@ class MainActivity : AppCompatActivity(), DocumentScannerFrameHandler.ResultHand
223225 documentScanner.run (image).getOrNull()?.pointsNormalized ? : throw IllegalStateException (
224226 " No document detected"
225227 )
228+ val polygonCrop = polygon.takeIf { it.isNotEmpty() && it.size == 4 } ? : PolygonHelper .getFullPolygon()
229+ var documentImage = ScanbotSdkImageProcessor .create()
230+ .crop(image, polygonCrop)
231+ .getOrThrow()
232+ documentImage = ScanbotSdkImageProcessor .create().resize(documentImage, 200 ).getOrThrow()
226233
227- val documentImage =
228- ImageProcessor (image).resize(200 ).crop(polygon).processedBitmap().getOrNull()
229234 resultView.post {
230- val bm = image.toBitmap()
231- when (bm){
232- is Result .Success <* > -> {}
233- is Result .Unexpected -> { throw IllegalStateException (bm.message) }
234- }
235- resultView.setImageBitmap(bm.getOrNull())
235+ resultView.setImageBitmap(documentImage.toBitmap().getOrNull())
236236 }
237237
238238 // continue scanning
0 commit comments