I am using @zxing/ngx-scanner to scan barcodes. I can scan barcodes of format QR_CODE and DATA_MATRIX using my laptop camera. I now want to scan barcode of format CODE_128. But the library takes time to scan and when it scans..it scans incorrectly.
Has anyone faced similar issues? How do I rectify this issue?
I am using Angular 7 and ngx-scanner version 2.0.1. I am trying in Chrome browser on Windows 10.
Code:
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);
}
}
The issue is resolved. For 1-D barcodes, we need to hold the barcode horizontally for it to scan correctly.
For more info, I had created github issue for the same: https://github.com/zxing-js/ngx-scanner/issues/296