Skip to content

Commit 3ea6607

Browse files
committed
fix manual processing module
1 parent f1f936b commit 3ea6607

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

classic-components-example/manual-processing/src/main/java/io/scanbot/example/ExampleApplication.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.scanbot.example
22

33
import android.app.Application
4-
import io.scanbot.sap.SdkFeature
54
import io.scanbot.sdk.ScanbotSDK
65
import io.scanbot.sdk.ScanbotSDKInitializer
76
import io.scanbot.sdk.util.log.LoggerProvider
@@ -24,11 +23,9 @@ class ExampleApplication : Application() {
2423
.withLogging(true)
2524
// TODO 2/2: Enable the Scanbot SDK license key
2625
//.license(this, licenseKey)
27-
.licenceErrorHandler { status, feature, statusMessage ->
26+
.licenseErrorHandler { status, feature, statusMessage ->
2827
LoggerProvider.logger.d("ExampleApplication", "+++> License status: ${status.name}. Status message: $statusMessage")
29-
if (feature != SdkFeature.NoSdkFeature) {
30-
LoggerProvider.logger.d("ExampleApplication", "+++> Feature not available: ${feature.name}")
31-
}
28+
LoggerProvider.logger.d("ExampleApplication", "+++> Feature not available: ${feature.name}")
3229
}
3330
//.sdkFilesDirectory(this, getExternalFilesDir(null)!!)
3431
.initialize(this)
@@ -38,6 +35,6 @@ class ExampleApplication : Application() {
3835
val licenseInfo = ScanbotSDK(this).licenseInfo
3936
LoggerProvider.logger.d("ExampleApplication", "License status: ${licenseInfo.status}")
4037
LoggerProvider.logger.d("ExampleApplication", "License isValid: ${licenseInfo.isValid}")
41-
LoggerProvider.logger.d("ExampleApplication", "License expirationDate: ${licenseInfo.expirationDate}")
38+
LoggerProvider.logger.d("ExampleApplication", "License expirationDate: ${licenseInfo.expirationDateString}")
4239
}
4340
}

classic-components-example/manual-processing/src/main/java/io/scanbot/example/MainActivity.kt

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.scanbot.example
22

3-
import android.graphics.BitmapFactory
43
import android.net.Uri
54
import android.os.Bundle
65
import android.util.Log
@@ -9,12 +8,15 @@ import androidx.activity.result.PickVisualMediaRequest
98
import androidx.activity.result.contract.ActivityResultContracts
109
import androidx.appcompat.app.AppCompatActivity
1110
import androidx.lifecycle.lifecycleScope
11+
import io.scanbot.common.getOrNull
12+
import io.scanbot.common.getOrThrow
1213
import io.scanbot.example.common.Const
1314
import io.scanbot.example.common.applyEdgeToEdge
1415
import io.scanbot.example.common.showToast
1516
import io.scanbot.example.databinding.ActivityMainBinding
1617
import io.scanbot.sdk.ScanbotSDK
17-
import io.scanbot.sdk.imagefilters.ParametricFilter
18+
import io.scanbot.sdk.image.ImageRef
19+
import io.scanbot.sdk.imageprocessing.ParametricFilter
1820
import io.scanbot.sdk.util.PolygonHelper
1921
import kotlinx.coroutines.Dispatchers
2022
import kotlinx.coroutines.launch
@@ -26,21 +28,22 @@ class MainActivity : AppCompatActivity() {
2628

2729
private val scanbotSdk: ScanbotSDK by lazy { ScanbotSDK(this) }
2830

29-
private val selectGalleryImageResultLauncher = registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
30-
if (!scanbotSdk.licenseInfo.isValid) {
31-
this@MainActivity.showToast("1-minute trial license has expired!")
32-
Log.e(Const.LOG_TAG, "1-minute trial license has expired!")
33-
return@registerForActivityResult
34-
}
31+
private val selectGalleryImageResultLauncher =
32+
registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
33+
if (!scanbotSdk.licenseInfo.isValid) {
34+
this@MainActivity.showToast("1-minute trial license has expired!")
35+
Log.e(Const.LOG_TAG, "1-minute trial license has expired!")
36+
return@registerForActivityResult
37+
}
3538

36-
if (uri == null) {
37-
showToast("Error obtaining selected image!")
38-
Log.e(Const.LOG_TAG, "Error obtaining selected image!")
39-
return@registerForActivityResult
40-
}
39+
if (uri == null) {
40+
showToast("Error obtaining selected image!")
41+
Log.e(Const.LOG_TAG, "Error obtaining selected image!")
42+
return@registerForActivityResult
43+
}
4144

42-
lifecycleScope.launch { processImage(uri) }
43-
}
45+
lifecycleScope.launch { processImage(uri) }
46+
}
4447

4548
override fun onCreate(savedInstanceState: Bundle?) {
4649
super.onCreate(savedInstanceState)
@@ -58,11 +61,17 @@ class MainActivity : AppCompatActivity() {
5861

5962
val page = withContext(Dispatchers.Default) {
6063
val inputStream = contentResolver.openInputStream(imageUri)
61-
val bitmap = BitmapFactory.decodeStream(inputStream)
62-
val detectedPolygon = scanbotSdk.createDocumentScanner().scanFromBitmap(bitmap)?.pointsNormalized ?: PolygonHelper.getFullPolygon()
64+
?: throw IllegalStateException("Cannot open input stream from URI: $imageUri")
65+
val image = ImageRef.fromInputStream(inputStream)
66+
val scanner = scanbotSdk.createDocumentScanner().getOrThrow()
67+
val detectedPolygon =
68+
scanner.run(image).getOrNull()?.pointsNormalized ?: PolygonHelper.getFullPolygon()
6369
val document = scanbotSdk.documentApi.createDocument()
64-
return@withContext document.addPage(bitmap).apply {
65-
apply(newPolygon = detectedPolygon, newFilters = listOf(ParametricFilter.grayscaleFilter()))
70+
return@withContext document.addPage(image).apply {
71+
apply(
72+
newPolygon = detectedPolygon,
73+
newFilters = listOf(ParametricFilter.grayscaleFilter())
74+
)
6675
}
6776
}
6877

0 commit comments

Comments
 (0)