These days we can easily find QR codes in most of the places like grocery stores, shopping malls, railway stations, airports, restaurants, hotels etc. Windows provides a basic camera preview that launches a dialog to control of the camera barcode scanner.Ĭall ClaimedBarcodeScanner.ShowVideoPreview to open the dialog and ClaimedBarcodeScanner.HideVideoPreview to close it.QR codes are the easiest and fastest way to share any type of information. RootPage.NotifyUser("Failed to create a barcode scanner object", NotifyType.ErrorMessage) Ī camera preview is required to help the user aim the camera at a barcode. RootPage.NotifyUser("Failed to claim the selected barcode scanner", NotifyType.ErrorMessage) SelectedScanner = await BarcodeScanner.FromIdAsync(scannerDeviceId) ĬlaimedScanner = await selectedScanner.ClaimScannerAsync() private async Task SelectScannerAsync(string scannerDeviceId) Var deviceId = selectedScannerInfo.DeviceId Ĭall BarcodeScanner.ClaimScannerAsync to obtain exclusive use of the camera barcode scanner. ![]() ![]() Var selectedScannerInfo = (BarcodeScanner)args.AddedItems private async void ScannerSelection_Changed(object sender, SelectionChangedEventArgs args) When the SelectedIndex of the ListBox changes (the first item is selected by default in the previous snippet), we query the device info (the SelectScannerAsync task is implemented in Step 6: Claim the camera barcode scanner). Private async void Watcher_Added(DeviceWatcher sender, DeviceInformation args)Īwait Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>īarcodeScanners.Add(new BarcodeScanner(args.Name, args.Id)) In the following snippet, we add each available scanner to a BarcodeScanner collection and bind the collection to a ListBox. When the DeviceWatcher starts (see Step 4: Enumerate barcode scanners), it enumerates through each connected device. If there is more than one camera, and they are built into the chassis of the computer, the name might differentiate between front and rear cameras. Microsoft BarcodeScanner ( name of your camera here) If you have more than one camera barcode scanner you might want to build a separate collection that excludes physical barcode scanners.Ĭamera barcode scanners using the decoder that ships with Windows are identified as: A non-NULL VideoDeviceID indicates that the barcode scanner object from your device collection is a camera barcode scanner. ![]() Step 5: Identify camera barcode scannersĪ camera barcode scanner consists of a camera (attached to a computer) combined with a software decoder, which Windows dynamically pairs to create a fully functional barcode scanner for Universal Windows Platform (UWP) apps.īarcodeScanner.VideoDeviceID can be used to differentiate between camera barcode scanners and physical barcode scanners. However, if the list of barcode scanners could change during the lifespan of your application, use a DeviceWatcher instead.įor more information, see Enumerate and watch devices and DeviceWatcher. If you do not expect the list of devices to change during the lifespan of your application, use DeviceInformation.FindAllAsync to get a one-time snapshot. Option B: Find all barcode scanners based on scope (for this example, we filter on Local connection type) string selector = BarcodeScanner.GetDeviceSelector(PosConnectionTypes.Local) ĭeviceInformationCollection deviceCollection = await DeviceInformation.FindAllAsync(selector) Option A: Find all barcode scanners string selector = BarcodeScanner.GetDeviceSelector() Use one of the BarcodeScanner.GetDeviceSelector methods to obtain a BarcodeScanner object for each connected barcode scanner. The Webcam capability is required for the software decoder to receive frames from the camera to both decode the barcode and provide a preview in your application.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |