Skip to content

Commit e30782e

Browse files
docs: fixed wrong code snippet for retrieving original image
1 parent 125e112 commit e30782e

File tree

1 file changed

+17
-9
lines changed
  • programming/javascript/user-guide

1 file changed

+17
-9
lines changed

programming/javascript/user-guide/index.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -504,15 +504,23 @@ await cvRouter.startCapturing("ReadSingleBarcode");
504504
Please be aware that it is necessary to update the `CapturedResultReceiver` object to obtain the original image. For instance:
505505
506506
```javascript
507-
const EnumCRIT = Dynamsoft.Core.EnumCapturedResultItemType;
508-
resultReceiver.onDecodedBarcodesReceived = (result) => {
509-
if (result.barcodeResultItems?.length) {
510-
// Use a filter to get the image on which barcodes are found.
511-
let image = result.items.filter(
512-
item => item.type === EnumCRIT.CRIT_ORIGINAL_IMAGE
513-
)[0].imageData;
514-
}
515-
};
507+
const EnumCRIT = Dynamsoft.Core.EnumCapturedResultItemType; // Enum for captured result item types.
508+
// Create a result receiver to handle the results.
509+
cvRouter.addResultReceiver({
510+
// This function is called when any capture result is received.
511+
onCapturedResultReceived: (result) => {
512+
//Check for barcode results
513+
let barcodeResultItems = result.items.filter((item) => item.type === EnumCRIT.CRIT_BARCODE);
514+
if (barcodeResultItems.length > 0) {
515+
let image = result.items.filter((item) => item.type === EnumCRIT.CRIT_ORIGINAL_IMAGE)[0]?.imageData; // Retrieve the original image.
516+
if (image) document.body.appendChild(image.toCanvas()); // Append the image to DOM.
517+
for (let item of barcodeResultItems) {
518+
// Print each barcode result to the console.
519+
console.log(`Barcode: ${item.text}, Format: ${item.formatString}`);
520+
}
521+
}
522+
},
523+
});
516524
```
517525
518526
#### 1.3. Change reading frequency to save power

0 commit comments

Comments
 (0)