【发布时间】:2020-04-29 09:14:10
【问题描述】:
我正在使用@zxing/ngx-scanner 扫描条形码。我可以使用笔记本电脑的摄像头扫描 QR_CODE 和 DATA_MATRIX 格式的条形码。我现在想扫描 CODE_128 格式的条码。但是图书馆需要时间来扫描,当它扫描时......它扫描不正确。
有没有人遇到过类似的问题?我该如何解决这个问题?
我正在使用 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);
}
}
【问题讨论】:
-
您确定它是 CODE_128 条码吗?一维条码有多种类型。
-
@ChrisBD 不能 100% 确定.. 但收到的样本似乎是 CODE_128... 附上我需要扫描的样本条码。
标签: angular angular7 zxing barcode-scanner