我正在使用@zxing/ngx-scanner扫描条形码。我可以用我的笔记本电脑相机扫描QR_CODE和DATA_MATRIX格式的条形码。我现在要扫描CODE_128格式的条形码。但是库需要时间来扫描,并且当它scans..it扫描不正确时。
有没有人遇到过类似的问题?我该如何纠正这个问题?
我使用的是Angular 7和ngx-scanner版本2.0.1。我正尝试在Windows 10上使用Chrome浏览器。
代码:
In HTML:
<zxing-scanner #scanner start="true" (scanSuccess)="myFn($event)" [formats]="['QR_CODE', 'EAN_13', 'CODE_128', 'DATA_MATRIX']"></zxing-scanner>
In ts:
import { ZXingScannerComponent } from '@zxing/ngx-scanner';
export class myClass implements OnInit {
@ViewChild('scanner') scanner: ZXingScannerComponent;
hasDevices: boolean = false;
hasPermission: boolean;
availableDevices: MediaDeviceInfo[] = [];
currentDevice: MediaDeviceInfo;
constructor(private zone: NgZone) {
window['angularComponentReference'] = {
zone: this.zone,
componentFn: (searchcontent: any) =>
window['scannerOutput'](searchcontent),
component: this,
};
}
ngOnInit() {
this.scanner.camerasFound.subscribe((devices: MediaDeviceInfo[]) => {
this.hasDevices = true;
this.availableDevices = devices;
});
this.scanner.camerasNotFound.subscribe(() => {
this.hasDevices = false;
});
this.scanner.scanComplete.subscribe((result: Result) => {
this.qrResult = result;
this.hasPermission = false;
});
this.scanner.permissionResponse.subscribe((perm: boolean) => {
this.hasPermission = perm;
});
}
myFn(resultString) {
console.log(resultString);
}
}
更新:我需要扫描的条形码样本
发布于 2020-05-03 00:44:14
问题已解决。对于一维条形码,我们需要水平握住条形码才能正确扫描。
为了获得更多信息,我为同样的问题创建了github问题:https://github.com/zxing-js/ngx-scanner/issues/296
https://stackoverflow.com/questions/61498210
复制相似问题