Skip to content

Commit a2de557

Browse files
committed
fix image-ref usage logic
1 parent f4aef69 commit a2de557

File tree

1 file changed

+8
-8
lines changed
  • classic-components-example/camera-view/src/main/java/io/scanbot/example

1 file changed

+8
-8
lines changed

classic-components-example/camera-view/src/main/java/io/scanbot/example/MainActivity.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ import io.scanbot.sdk.document.DocumentScannerFrameHandler
3333
import io.scanbot.sdk.documentscanner.DocumentDetectionStatus
3434
import io.scanbot.sdk.documentscanner.DocumentScanner
3535
import io.scanbot.sdk.image.ImageRef
36+
import io.scanbot.sdk.imageprocessing.ScanbotSdkImageProcessor
3637
import io.scanbot.sdk.process.ImageProcessor
3738
import io.scanbot.sdk.ui.PolygonView
3839
import io.scanbot.sdk.ui.camera.ScanbotCameraXView
3940
import io.scanbot.sdk.ui.camera.ShutterButton
41+
import io.scanbot.sdk.util.PolygonHelper
4042

4143
class 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

Comments
 (0)