使用Scan Kit(统一扫码服务),通过接数组生成码图

使用Scan Kit(统一扫码服务),通过接数组生成码图

HarmonyOS
2024-08-07 09:18:24
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
椰椰蓉螈
// 通过接数组生成码图 Promise方式
      Button('生成乘车码').genButton()
        .onClick(() => {
          this.pixelMap = undefined;
          let content = this.mContext;
          let pattern = /^[0-9a-fA-F]+$/;
          if (content && !pattern.test(content)) {
            promptAction.showToast({
              message: '乘车码是通过字节数组生成,请输入十六进字符串表示的字节数组',
              duration: 2000
            });
            return;
          }
          if (content.length % 2 !== 0) {
            content = '0' + content;
          }
          let contentBuffer: ArrayBuffer = buffer.from(content, 'hex').buffer;
          let options: generateBarcode.CreateOptions = {
            scanType: this.mScanType,
            height: Number(this.mHeight),
            width: Number(this.mWidth),
            margin: Number(this.mMargin),
            level: this.mLevel,
            backgroundColor: this.mBackgroundColor,
            pixelMapColor: this.mPixelMapColor,
          }

          try {
            generateBarcode.createBarcode(contentBuffer, options).then((result: image.PixelMap) => {
              this.pixelMap = result;
              hilog.info(0x0001, TAG, 'Succeeded in creating barCode.');
            }).catch((error: BusinessError) => {
              showError(error);
              hilog.error(0x0001, TAG,
                `catch Failed to create barCode. Code: ${error.code}, message: ${error.message}`);
            })
          } catch (error) {
            showError(error);
            hilog.error(0x0001, TAG, `000 Failed to create barCode. Code: ${error.code}, message: ${error.message}`);
          }
        })
分享
微博
QQ
微信
回复
2024-08-07 11:25:35
相关问题
Scan Kit无法识别多个
1511浏览 • 1回复 待解决
相册识别多失败
1537浏览 • 1回复 待解决
ArkTs怎么实现一扫功能?
4165浏览 • 1回复 待解决
JS如何实现手机功能?
2641浏览 • 1回复 待解决
HarmonyOS 需要实现音效播放问题
124浏览 • 1回复 待解决
自定义界面预览画面出现拉伸
1627浏览 • 1回复 待解决
AI生成能力中文字符乱码
9182浏览 • 1回复 待解决
Arkts开发 api9 中怎么实现功能?
2661浏览 • 1回复 待解决
openHarmony-Api8项目,如何生成二维
669浏览 • 0回复 待解决
HarmonyOS 如何获取mnc
92浏览 • 1回复 待解决