【发布时间】:2020-10-28 10:46:28
【问题描述】:
我想扫描图像中的所有一维条形码。 我正在使用@zxingjs/library,我可以扫描 1 个条形码,但不是全部。 我怎么能用nodejs做到这一点? 我知道有一个接口 MUltipleBarcodeReader 有 2 个方法,但我不知道如何在我的原型中使用它。
这是MultipleBarcodeReader
import BinaryBitmap from '../BinaryBitmap';
import DecodeHintType from '../DecodeHintType';
import Result from '../Result';
/**
* Implementation of this interface attempt to read several barcodes from one image.
*
* @see com.google.zxing.Reader
* @author Sean Owen
*/
export default interface MultipleBarcodeReader {
/**
* @throws NotFoundException
*/
decodeMultiple(image: BinaryBitmap): Result[];
/**
* @throws NotFoundException
*/
decodeMultiple(image: BinaryBitmap, hints: Map<DecodeHintType, any>): Result[];
}
这是我的原型:
const {MultipleBarcodeReader} = require('@zxing/library/esm/core/multi/MultipleBarcodeReader');
//I read image with fs and decode it
//hints
const multipleBarcodeReader = new MultipleBarcodeReader();
multipleBarcodeReader.setHints(hints);
const multipleResult = multipleBarcodeReader.decodeMultiple(binaryBitmap)
当我运行我的原型时,它给了我这个错误:
const multipleBarcodeReader = new MultipleBarcodeReader();
^
TypeError: MultipleBarcodeReader is not a constructor
at Object.<anonymous> (C:\Users\awais.ahmed\Desktop\ZXing\index.js:27:31)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47
谢谢
【问题讨论】:
-
您提供了很多信息,很有帮助!但是,如果您在 Google 上搜索“javascript 不是构造函数”,您可能会节省一些时间。结果包括 MDN 的页面
TypeError: "x" is not a constructor -
好的,谢谢。 MultipleBarcodeReader 是一个接口,那么我如何在我的原型中访问这个接口和他的方法?