From 4d0bc26a86e9ae58a2e030faabbae75676a09855 Mon Sep 17 00:00:00 2001 From: yeliulee Date: Thu, 25 Jul 2024 20:36:33 +0800 Subject: [PATCH 1/2] implement analyzeImage for ohos --- ohos/src/main/ets/MobileScannerPlugin.ets | 39 +++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/ohos/src/main/ets/MobileScannerPlugin.ets b/ohos/src/main/ets/MobileScannerPlugin.ets index 376fb64..e625bd4 100644 --- a/ohos/src/main/ets/MobileScannerPlugin.ets +++ b/ohos/src/main/ets/MobileScannerPlugin.ets @@ -26,9 +26,10 @@ import Log from '@ohos/flutter_ohos/src/main/ets/util/Log'; import { AbilityAware, AbilityPluginBinding, ByteBuffer } from '@ohos/flutter_ohos/index'; import { UIAbility } from '@kit.AbilityKit'; import { cameraPermission, checkPermissions, requestPermissions } from './CameraPermissions'; -import { customScan, scanBarcode, scanCore } from '@kit.ScanKit'; +import { customScan, detectBarcode, scanBarcode, scanCore } from '@kit.ScanKit'; import EventChannel, { EventSink } from '@ohos/flutter_ohos/src/main/ets/plugin/common/EventChannel'; import { Barcode, BarcodeFormat, BarcodeType } from './Barcode'; +import { fileUri } from '@kit.CoreFileKit'; const TAG: string = "mobile_scanner"; @@ -246,7 +247,41 @@ export class MobileScannerPlugin implements FlutterPlugin, MethodCallHandler, Ab } analyzeImage(call: MethodCall, result: MethodResult) { - result.notImplemented() + const path: string = call.args + let inputImage: detectBarcode.InputImage + + if(path.startsWith('file://')) { + inputImage = { + uri: path + } + } else { + inputImage = { + uri: fileUri.getUriFromPath(path) + } + } + + const options: scanBarcode.ScanOptions = { + enableMultiMode: true, + } + + detectBarcode.decode(inputImage, options).then((r) => { + const _r: Barcode[] = r.map(item => { + return { + displayValue: item.originalValue, + rawValue: item.originalValue, + format: BarcodeFormat.unknown, + type: BarcodeType.unknown, + } as Barcode; + }); + this.analyzerCallback(_r); + result.success(_r.length > 0); + }).catch((e: Error) => { + result.error( + "MobileScanner", + `Failed to analyze image, ${e.message}`, + null + ) + }) } setScale(call: MethodCall, result: MethodResult) { -- Gitee From d8045b5e807b00e6d83c256730ea8ba6d8a88259 Mon Sep 17 00:00:00 2001 From: yeliulee Date: Thu, 25 Jul 2024 20:55:22 +0800 Subject: [PATCH 2/2] implement analyzeImage for ohos Signed-off-by: yeliulee --- ohos/src/main/ets/MobileScannerPlugin.ets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ohos/src/main/ets/MobileScannerPlugin.ets b/ohos/src/main/ets/MobileScannerPlugin.ets index e625bd4..d65f448 100644 --- a/ohos/src/main/ets/MobileScannerPlugin.ets +++ b/ohos/src/main/ets/MobileScannerPlugin.ets @@ -62,7 +62,6 @@ export class MobileScannerPlugin implements FlutterPlugin, MethodCallHandler, Ab private surfaceId: string | null = null; private binding: FlutterPluginBinding | null = null; private isStart = false; - private cameraWidth: number = 0; private cameraHeight: number = 0; @@ -74,7 +73,8 @@ export class MobileScannerPlugin implements FlutterPlugin, MethodCallHandler, Ab this.binding = binding; this.applicationContext = binding.getApplicationContext(); - this.methodChannel = new MethodChannel(binding.getBinaryMessenger(), "dev.steenbakker.mobile_scanner/scanner/method"); + this.methodChannel = + new MethodChannel(binding.getBinaryMessenger(), "dev.steenbakker.mobile_scanner/scanner/method"); this.methodChannel.setMethodCallHandler(this); this.eventChannel = new EventChannel(binding.getBinaryMessenger(), "dev.steenbakker.mobile_scanner/scanner/event"); @@ -250,7 +250,7 @@ export class MobileScannerPlugin implements FlutterPlugin, MethodCallHandler, Ab const path: string = call.args let inputImage: detectBarcode.InputImage - if(path.startsWith('file://')) { + if (path.startsWith('file://')) { inputImage = { uri: path } -- Gitee