TTMSFNCWXQRDecoder
The TTMSFNCWXQRDecoder component decodes QR codes from still images. Images can be supplied as a file, a Base64 string, or a TTMSFNCBitmap. The component can also be connected to a TTMSFNCWXCamera for continuous live decoding. This component uses the jsQR library.
Notice
With the default settings this component requires internet connection. If you'd like to run the component in an offline environment, please change the LibraryLocation property. Read more about this at the Loading modes paragraph of this documentation.
Decoding a single image
procedure TForm1.Button1Click(Sender: TObject);
begin
// From file (not available for WEB):
TMSFNCWXQRDecoder1.DecodeFromFile('C:\images\qrcode.png');
end;
procedure TForm1.TMSFNCWXQRDecoder1Decoded(Sender: TObject;
AFound: Boolean; AResult: string);
begin
if AFound then
ShowMessage('QR Code: ' + AResult)
else
ShowMessage('No QR code found.');
end;
Decoding from a Base64 string
If you have a Base64 string with a known filename suffix (useful for format detection), use DecodeFromBase64WithFilename:
Decoding from a bitmap
Connect with TTMSFNCWXCamera
Assign a TTMSFNCWXCamera to the Camera property for continuous live QR code scanning:
procedure TForm1.FormCreate(Sender: TObject);
begin
TMSFNCWXQRDecoder1.Camera := TMSFNCWXCamera1;
TMSFNCWXCamera1.Start;
end;
procedure TForm1.TMSFNCWXQRDecoder1Decoded(Sender: TObject;
AFound: Boolean; AResult: string);
begin
if AFound then
begin
Label1.Caption := 'Scanned: ' + AResult;
TMSFNCWXCamera1.Stop;
end;
end;
Improve decoding
When decoding via the camera, decoding happens by analyzing continuous snapshots. If the success rate is low (especially on mobile), try the following:
- Resolution — Increase
TTMSFNCWXCamera.Resolution.IdealWidthandIdealHeight(default is640x480). The ideal resolution refers to a resolution that cannot be guaranteed (e.g. the selected camera module does not support it), however the underlying API will try to select one as close to it as possible. Higher resolution can improve barcode detection but uses more memory. - Lighting and framing — Ensure the barcode is fully visible and well-lit. Dark or blurry images reduce accuracy.
- Camera module — On Android, the default back-facing camera is often a wide-angle lens which can distort barcodes. Use
RequestDevicesandSelectDeviceto choose a different camera. See Camera device selection.
Loading modes (LibraryLocation)
Most of the WX components offer the option to load the JavaScript library it depends on either online or offline. This option can be set via the LibraryLocation property. The available options means the following:
llOnline: The JavaScript library will be loaded live from an external URL. This allows a faster loading of the library, decreasing the loading time of the component and providing a better performance. However, this option also requires an active internet connection.llOffline: The JavaScript library will be loaded from resources. This guarantees the component is going to work in offline mode, but performance can decrease, especially on less powerful devices.
When you are ready to deploy your application, consider the differences above and make a choice based on them.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
Camera |
TTMSFNCWXCamera |
nil |
Assign a camera component for live continuous QR code decoding. |
LibraryLocation |
TTMSFNCWXLibraryLocation |
llOnline |
Controls whether jsQR is loaded from CDN or embedded resources. |
Methods
| Method | Description |
|---|---|
DecodeFromBase64(ABase64; ACallback) |
Decodes a Base64-encoded image. ACallback is called when processing is complete. |
DecodeFromBase64WithFilename(ABase64, AFileName; ACallback) |
Decodes a Base64 image with an associated filename for format hints. |
DecodeFromFile(AFileName; ACallback) |
Decodes a file. Not available for WEB. ACallback is called when processing is complete. |
DecodeFromImage(ABitmap; ACallback) |
Decodes a TTMSFNCBitmap. ACallback is called when processing is complete. |
Events
| Event | Parameters | Description |
|---|---|---|
OnDecoded |
AFound: Boolean; AResult: string |
Fires each time an image is processed. AFound is True if a QR code was decoded. AResult contains the decoded text. |