Namespace: SpawnDev.SpawnJS.JSObjects
Inherits: SpawnJSObject
Source: JSObjects/BarcodeDetector.cs
MDN Reference: BarcodeDetector on MDN
The BarcodeDetector interface of the Barcode Detection API allows detection of linear and two dimensional barcodes in images. https://developer.mozilla.org/en-US/docs/Web/API/BarcodeDetector
| Signature | Description |
|---|---|
BarcodeDetector() |
The BarcodeDetector() constructor creates a new BarcodeDetector object which detects linear and two-dimensional barcodes in images. |
BarcodeDetector(BarcodeDetectorOptions options) |
The BarcodeDetector() constructor creates a new BarcodeDetector object which detects linear and two-dimensional barcodes in images. |
BarcodeDetector(SpawnJSObjectReference _ref) |
Deserialization constructor |
| Method | Return Type | Description |
|---|---|---|
GetSupportedFormats() |
Task<List<string>> |
The getSupportedFormats() static method of the BarcodeDetector interface returns a Promise which fulfills with an Array of supported barcode format types. |
IsDefined() |
bool |
Checks if BarcodeDetector is defined in the global scope |
Detect(Union<Blob, Element, ImageData, ImageBitmap, OffscreenCanvas> imageBitmapSource) |
Task<Array<DetectedBarcode>> |
The detect() method of the BarcodeDetector interface returns a Promise which fulfills with an Array of detected barcodes within an image. Receives an ImageBitmapSource as a parameter. This can be an element, a Blob of type image or an ImageData object. |
SpawnDev.SpawnJS Mapping Note: The JavaScript examples below show the standard Web API usage. In SpawnDev.SpawnJS, the same API is available with C# conventions:
- Properties and methods use PascalCase (e.g.,
readyStatebecomesReadyState)- Events use ActionEvent with
+=/-=(e.g.,addEventListener("click", fn)becomesOnClick += handler)- Async methods return
Task<T>instead ofPromise<T>- Objects should be disposed with
usingstatements- Access via
JS.Get<BarcodeDetector>(...)or constructornew BarcodeDetector(...)
// check compatibility
if (!("BarcodeDetector" in globalThis)) {
console.log("Barcode Detector is not supported by this browser.");
} else {
console.log("Barcode Detector supported!");
// create new detector
const barcodeDetector = new BarcodeDetector({
formats: ["code_39", "codabar", "ean_13"],
});
}// check supported types
BarcodeDetector.getSupportedFormats().then((supportedFormats) => {
supportedFormats.forEach((format) => console.log(format));
});barcodeDetector
.detect(imageEl)
.then((barcodes) => {
barcodes.forEach((barcode) => console.log(barcode.rawValue));
})
.catch((err) => {
console.log(err);
});