Getting Started |
Getting Started Guide for Scandit BarcodeScanner for Windows
This document show how to get started using the Scandit BarcodeScanner SDK. It first starts by showing how to run the samples and describes the steps to add the SDK to your Windows 10 application.
All samples are contained in Samples.sln solution file. It contains samples targetting Windows Desktop applications and Windows 10 Universal Store apps.
The simple sample project SimpleSampleUniversal show the basic usage of the barcode picker API in the Store apps, whereas the CommandLineQrCodeScanner and NativeBarcodeScanner samples shows how to use Scandit Recognition package in desktop apps.
Before running the samples, you will have to replace the Scandit Application Key placeholder with your own app key that is visible in your Scandit Account. The application key has to be placed in MainPage.xaml.cs. The place holder looks like this:
static string ScanditBarcodeScannerAppKey = "-- ENTER YOUR SCANDIT LICENSE KEY HERE --";
This section describes the steps to use the Scandit BarcodeScanner in your Windows 10 Application. A simple project example that illustrates how to do this is included in the SimpleSampleUniversal project included in Samples.sln.
The barcode scanner is bundled as a NuGet package and you can install it through the NuGet package manager. You can do this in the package manager console, or from the UI in Visual Studio. In the following the steps for adding the package from the Visual Studio UI are described:
The Windows 10 universal package supports all architectures (x86, ARM, x64). Please note that it is currently not possible build/run your project when the AnyCPU is selected. You will need to select the x64/x86/ARM depending on your current target platform.
You will need to make a few adjustments to the App Manifest.
<Extensions> <Extension Category="windows.activatableClass.inProcessServer"> <InProcessServer> <Path>VideoInputRT.dll</Path> <ActivatableClass ActivatableClassId="VideoInputRT.FrameAccess" ThreadingModel="both" /> </InProcessServer> </Extension> </Extensions>
It is possible to instantiate the barcode picker directly in your application code. However, the simplest solution is to instantiate the barcode picker inside the xaml file as shown below:
<Page ... xmlns:scandit="using:Scandit.BarcodePicker"> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <scandit:BarcodePicker x:Name="thePicker" /> </Grid> </Page>
Before starting the scanning process, you must set the Scandit license key to the application key you obtained on the Scandit.com website. If you do not set the application key, you will not be able to scan any barcodes and an error message will be displayed on top of the camera stream. For versions prior to 4.12, the application would terminate upon instantiating the picker.
ScanditLicense.AppKey = "-- ENTER YOUR SCANDIT LICENSE KEY HERE --";
The scanning process is configured through scan settings. Scan settings control the enabled symbologies (barcode types) and allow to fine-tune the recognition behavior. By default, scanning of all barcode symbologies is disabled and you must explicitly enable the symbologies you require in your application.
var scanSettings = new ScanSettings(); // enable a bunch of symbologies for scanning. Note that it's best to // only enable barcode symbologies that you are actually going to use // in your application as every symbology adds a processing overhead. var symbologiesToEnable = new BarcodeSymbology[] { BarcodeSymbology.Ean13, BarcodeSymbology.Upca, BarcodeSymbology.Ean8, BarcodeSymbology.Upce, }; foreach (var sym in symbologiesToEnable) scanSettings.EnableSymbology(sym); // apply the settings to the picker await picker.ApplySettingsAsync(scanSettings);
To get informed when a new barcode has been recognized, add a DidScan delegate to the barcode picker. Additionally, it's good practice to also register a Failed delegate to get notified and react to failures of the picker.
// gets called whenever the picker encounters an error, e.g. the camera // could not be initialized. picker.Failed += PickerFailed; // gets called whenever a new barcode has been recognized. This is where // you put your custom logic for handling barcode scan results. picker.DidScan += OnCodeScanned;
private void OnCodeScanned(ScanSession session) { foreach (var code in session.NewlyRecognizedCodes) Debug.WriteLine("{0}: {1}", code.SymbologyString, code.Data); }
Before any codes can be scanned, the BarcodePicker muste be started. This can be done by calling OpenCameraAndStartScanningAsync(DeviceInformation).
var camera = await CameraSelection.FindBackFacingCameraOrDefault(); await picker.OpenCameraAndStartScanningAsync(camera);
When your are done, make sure to close the camera and stop the scanning with StopScanningAndCloseCameraAsync.
await picker.StopScanningAndCloseCameraAsync();
The GPU acceleration support of the Windows SDK requires the ANGLE framework to translate OpenGL ES calls to Direct3D. For licensing reasons the ANGLE dependency is not included by default and has to be added manually.
Currently GPU acceleration can only be used in UWP projects. Make sure you comply with the ANGLE software license. Add the ANGLE NuGet package version 2.1.13 or newer to your project using the NuGet package manager in Visual Studio. No additional actions are required. The Scandit SDK will detect the presence of ANGLE and enable GPU acceleration automatically.