@State pointX1: number = 0;
@State pointX3: number = 0;
@State pointY1: number = 0;
@State pointY3: number = 0;
@State left: number = 0;
@State right: number = 0;
@State top: number = 0;
@State bottom: number = 0;
@State g: number = 0;
@State k: number = 0;
@State gx: number = 0;
@State kx: number = 0;
// 单码成功识别回调接口
let left = result[0].scanCodeRect?.left as number
let right = result[0].scanCodeRect?.right as number
let top = result[0].scanCodeRect?.top as number
let bottom = result[0].scanCodeRect?.bottom as number
let x = (left + right) / 2 + this.cameraOffsetX
let y = (top + bottom) / 2
this.pointX1 = x as number
this.pointY1 = y as number
this.left = result[0].scanCodeRect?.left as number
this.right = result[0].scanCodeRect?.right as number
this.top = result[0].scanCodeRect?.top as number
this.bottom = result[0].scanCodeRect?.bottom as number
this.g = this.bottom - this.top
this.k = this.right - this.left
this.gx = this.g / 2
this.kx = this.k / 2
this.pointX3 = this.pointX1 - this.kx
this.pointY3 = this.pointY1 - this.gx
// 布局
Button().position({ x: this.pointX1, y: this.pointY1 }).width('5').height('5')
Button().position({ x: this.pointX3, y: this.pointY3 }).width('1px').height(this.g)
扫码startScan返回的scanCodeRect,其中的坐标也是右移的,使用预览流的宽高进行计算的值都是右移的,但是其和scanCodeRect是匹配的。
用屏幕的宽高(display获取的)和解码框宽高进行换算时,得出来的坐标没有问题。用cameraWidth/cameraHeight和解码框宽高进行换算时,得到的坐标整体右移动。这种坐标偏移问题是因为预览流和手机宽高不一样大小导致的吗?要如何解决呢?
预览流识别建议固定手机位置扫码。在示例代码的基础上添加如下代码: