HarmonyOS detectBarcode接口能力问题

按照以下文档使用detectBarcode.decode的识图二维码扫码能力

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/scan-imagedecode-V5

运行在模拟器上报以下错误

Device info:emulator
Build info:emulator 5.0.0.25(SP37DEVC00E25R4P11log)
Fingerprint:a5572fb9d9a7494e164622f6bbb9654de3ad3c8045afb1cbdab15e2f247da911
Module name:com.example.test_sensor
Version:1.0.0
VersionCode:1000000
PreInstalled:No
Foreground:No
Pid:24637
Uid:20020045
Reason:TypeError
Error name:TypeError
Error message:Cannot read property decode of undefined
SourceCode:
  detectBarcode.decode(inputImage, (error: BusinessError, result: Array<scanBarcode.ScanResult>) => {
    ^
    Stacktrace:
      at initQrCode (entry/src/main/ets/pages/Index.ets:63:7)
    at anonymous (entry/src/main/ets/pages/Index.ets:168:11)
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.

执行代码:

let inputImage: detectBarcode.InputImage = { uri: 'file://media/Photo/2/Image/Image.jpeg' }
detectBarcode.decode(inputImage, (error: BusinessError, result: Array<scanBarcode.ScanResult>) => {
  if (error && error.code) {
    hilog.error(0x0001, '[Scan Sample]',
      `Failed to get ScanResult by callback. Code: ${error.code}, message: ${error.message}`);
    return;
  }
  hilog.info(0x0001, '[Scan Sample]',
    `Succeeded in getting ScanResult by callback, result is ${JSON.stringify(result)}`);
});
//'file://media/Photo/2/Image/Image.jpeg' 是我通过文档样例的picker获取到的结果地址,是实际选取图片的地址,运行上述代码需要加上picker选图片获取到图片地址
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

try-catch上述代码没catch到有用的error信息。

如果是模拟器对于这个接口不支持,那我要怎么获取到 哪些接口能力在模拟器上不支持的信息呢?以及目前真机和模拟器都有哪些具体区别有文档说明吗

HarmonyOS
2024-12-23 16:41:33
1913浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

使用detectBarcode.decode的demo请参考:

import { scanBarcode, detectBarcode } from '@kit.ScanKit';
import { picker } from '@kit.CoreFileKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct RefreshExample {

  test(){
    // 通过picker拉起图库并选择图片
    let photoOption = new picker.PhotoSelectOptions();
    photoOption.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE;
    photoOption.maxSelectNumber = 1;
    let photoPicker = new picker.PhotoViewPicker();
    photoPicker.select(photoOption).then((result) => {
      // 定义识码参数inputImage,其中uri为picker选择图片
      let inputImage: detectBarcode.InputImage = { uri: result.photoUris[0] }
      // 调用图片识码接口
      detectBarcode.decode(inputImage, (error: BusinessError, result: Array<scanBarcode.ScanResult>) => {
        if (error && error.code) {
          hilog.error(0x0001, '[Scan Sample]', `Failed to get ScanResult by callback. Code: ${error.code}, message: ${error.message}`);
          return;
        }
        hilog.info(0x0001, '[Scan Sample]', `Succeeded in getting ScanResult by callback, result is ${JSON.stringify(result)}`);
      });
    })
  }
  @State isRefreshing: boolean = false

  count:number = 89
  build() {
    Column() {
      Button('点我选择图片')
        .onClick(()=>{
          this.test()
        })
    }.grayscale(1)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
分享
微博
QQ
微信
回复
2024-12-23 18:23:55


相关问题
HarmonyOS 接口声明问题
664浏览 • 1回复 待解决
HarmonyOS class实现接口问题
560浏览 • 1回复 待解决
HarmonyOS 使用下载能力的几个问题
737浏览 • 1回复 待解决
HarmonyOS startAbility能力使用上有问题
521浏览 • 1回复 待解决
HarmonyOS 图片风控接口问题
898浏览 • 1回复 待解决
HarmonyOS 蓝牙连接配对接口问题
846浏览 • 1回复 待解决
HarmonyOS Camera 和 Scan 相关接口问题
803浏览 • 1回复 待解决
HarmonyOS 更新测试版本接口问题
857浏览 • 1回复 待解决
NativeWindowFlushBuffer接口刷新问题
2547浏览 • 1回复 待解决
HarmonyOS ArkTS接口回调的案例问题
2242浏览 • 1回复 待解决
HarmonyOS 传参加密后调用接口问题
531浏览 • 1回复 待解决