BarCodeReader
BarCodeReader class
BarCodeReader encapsulates an image which may contain one or several barcodes, it then can perform ReadBarCodes operation to detect barcodes.
new BarCodeReader(image, areas, decodeTypes)
Initializes a new instance of the BarCodeReader
| Parameter | Description |
|---|---|
| image | encoded as base64 string or path to image |
| areas | array of object by type Rectangle |
| decodeTypes | the array of objects by DecodeType |
Example:
//This sample shows how to detect Code39 and Code128 barcodes.
let reader = new BarCodeReader("test.png", null, [DecodeType.CODE_39, DecodeType.CODE_128]);
let results = reader.readBarCodes();
for(let i = 0; i < results.length; i++)
{
let result = results[i];
console.log("BarCode Type: " + result.getCodeTypeName());
console.log("BarCode CodeText: " + result.getCodeText());
}
Methods
| Name | Description |
|---|---|
| importFromXml(xmlFile) (static) | Exports BarCode properties to the xml-file specified |
| containsAny() | Determines whether any of the given decode types is included into |
| exportToXml(xmlFile) | Exports BarCode properties to the xml-file specified |
| getBarCodeReadType() | Gets the decode type of the input barcode decoding |
| getBarcodeSettings() | The main BarCode decoding parameters. Contains parameters which make influence on recognized data. |
| getFoundBarCodes() | Gets recognized BarCodeResult array |
| getFoundCount() | Gets recognized barcodes count |
| getQualitySettings() | QualitySettings allows to configure recognition quality and speed manually. You can quickly set up QualitySettings by em |
| getTimeout() | Gets the timeout of recognition process in milliseconds. |
| readBarCodes() | Reads BarCodeResult from the image. |
| setBarCodeImage(imageResource, …areas) | Sets bitmap image and areas for recognition. Must be called before ReadBarCodes() method. |
| setBarCodeReadType(…types) | Sets SingleDecodeType type array for recognition. Must be called before readBarCodes() method. |
| setQualitySettings() | QualitySettings allows to configure recognition quality and speed manually. You can quickly set up QualitySettings by em |
| setTimeout(value) | Sets the timeout of recognition process in milliseconds. |
importFromXml(xmlFile) (static)
Exports BarCode properties to the xml-file specified
| Parameter | Description |
|---|---|
| xmlFile | The name of the file |
Returns: Whether or not export completed successfully. Returns True in case of success; False Otherwise
containsAny()
Determines whether any of the given decode types is included into
| Parameter | Description |
|---|---|
| …decodeTypes | Types to verify. |
Returns: bool Value is a true if any types are included into.
exportToXml(xmlFile)
Exports BarCode properties to the xml-file specified
| Parameter | Description |
|---|---|
| xmlFile | The name of the file |
Returns: Whether or not export completed successfully. Returns True in case of success; False Otherwise
getBarCodeReadType()
Gets the decode type of the input barcode decoding
Returns: *
getBarcodeSettings()
The main BarCode decoding parameters. Contains parameters which make influence on recognized data.
Returns: The main BarCode decoding parameters
getFoundBarCodes()
Gets recognized BarCodeResult array
Returns: recognized BarCodeResult array
Example:
//This sample shows how to read barcodes with BarCodeReader
let reader = new BarCodeReader("test.png", null, [ DecodeType.CODE_39, DecodeType.CODE_128 ]);
reader.readBarCodes();
for(let i = 0; reader.getFoundCount() > i; ++i)
console.log("BarCode CodeText: " + reader.getFoundBarCodes()[i].getCodeText());
getFoundCount()
Gets recognized barcodes count
Example:
//This sample shows how to read barcodes with BarCodeReader
let reader = new BarCodeReader("test.png", null, [ DecodeType.CODE_39, DecodeType.CODE_128 ]);
reader.readBarCodes();
for(let i = 0; reader.getFoundCount() > i; ++i)
console.log("BarCode CodeText: " + reader.getFoundBarCodes()[i].getCodeText());
Value: The recognized barcodes count
getQualitySettings()
QualitySettings allows to configure recognition quality and speed manually. You can quickly set up QualitySettings by embedded presets: HighPerformance, NormalQuality, HighQuality, MaxBarCodes or you can manually configure separate options. Default value of QualitySettings is NormalQuality.
Returns: QualitySettings to configure recognition quality and speed.
Example:
//This sample shows how to use QualitySettings with BarCodeReader
let reader = new BarCodeReader("test.png", null, null);
//set high performance mode
reader.setQualitySettings(QualitySettings.getHighPerformance());
let results = reader.readBarCodes();
for(let i = 0; i < results.length; i++)
{
let result = results[i];
console.log("BarCode CodeText: " + result.getCodeText());
}
getTimeout()
Gets the timeout of recognition process in milliseconds.
Returns: The timeout.
Example:
let reader = new BarCodeReader("test.png", null, null);
reader.setTimeout(5000);
let results = reader.readBarCodes();
for(let i = 0; i < results.length; i++)
{
let result = results[i];
console.log("BarCode CodeText: " + result.getCodeText());
}
readBarCodes()
Reads BarCodeResult from the image.
Returns: Returns array of recognized BarCodeResults on the image. If nothing is recognized, zero array is returned.
Example:
//This sample shows how to read barcodes with BarCodeReader
let reader = new BarCodeReader("test.png", null, [ DecodeType.CODE_39, DecodeType.CODE_128 ]);
let results = reader.readBarCodes();
for(let i = 0; i < results.length; i++)
{
let result = results[i];
console.log("BarCode CodeText: " + result.getCodeText());
}
let reader = new BarCodeReader("test.png", null, [ DecodeType.CODE_39, DecodeType.CODE_128 ]);
reader.readBarCodes();
for(let i = 0; reader.getFoundCount() > i; ++i)
console.log("BarCode CodeText: " + reader.getFoundBarCodes()[i].getCodeText());
setBarCodeImage(imageResource, …areas)
Sets bitmap image and areas for recognition. Must be called before ReadBarCodes() method.
| Parameter | Description |
|---|---|
| imageResource | The image for recognition. |
| areas | areas list for recognition |
Throws: BarcodeException
Example:
//This sample shows how to detect Code39 and Code128 barcodes.
let bmp = "test.png";
let reader = new BarCodeReader();
reader.setBarCodeReadType([ DecodeType.CODE_39, DecodeType.CODE_128 ]);
var img = new Image();
img.src = 'path_to_image';
width = img.width;
height = img.height;
reader.setBarCodeImage(bmp, new Rectangle[] { new Rectangle(0, 0, width, height) });
let results = reader.readBarCodes();
for(let i = 0; i < results.length; i++)
{
let result = results[i];
console.log("BarCode Type: " + result.getCodeTypeName());
console.log("BarCode CodeText: " + result.getCodeText());
}
setBarCodeReadType(…types)
Sets SingleDecodeType type array for recognition. Must be called before readBarCodes() method.
| Parameter | Description |
|---|---|
| types | The SingleDecodeType type array to read. |
Example:
//This sample shows how to detect Code39 and Code128 barcodes.
let reader = new BarCodeReader();
reader.setBarCodeReadType([ DecodeType.CODE_39, DecodeType.CODE_128 ]);
reader.setBarCodeImage("test.png");
let results = reader.readBarCodes();
for(let i = 0; i < results.length; i++)
{
let result = results[i];
console.log("BarCode Type: " + result.getCodeTypeName());
console.log("BarCode CodeText: " + result.getCodeText());
}
setQualitySettings()
QualitySettings allows to configure recognition quality and speed manually. You can quickly set up QualitySettings by embedded presets: HighPerformance, NormalQuality, HighQuality, MaxBarCodes or you can manually configure separate options. Default value of QualitySettings is NormalQuality.
Example:
//This sample shows how to use QualitySettings with BarCodeReader
let reader = new BarCodeReader("test.png", null, [ DecodeType.CODE_39, DecodeType.CODE_128 ]);
//set high performance mode
reader.setQualitySettings(QualitySettings.getHighPerformance());
let results = reader.readBarCodes();
for(let i = 0; i < results.length; i++)
{
let result = results[i];
console.log("BarCode CodeText: " + result.getCodeText());
}
setTimeout(value)
Sets the timeout of recognition process in milliseconds.
| Parameter | Description |
|---|---|
| value | The timeout. |
Example:
let reader = new BarCodeReader("test.png", null, null);
reader.setTimeout(5000);
let results = reader.readBarCodes();
for(let i = 0; i < results.length; i++)
{
let result = results[i];
console.log("BarCode CodeText: " + result.getCodeText());
}