Working with the New Scanning APIs in Windows 8.1


With Windows 8.1, Microsoft has introduced a lot of new programmatic capabilities. One of the features announced as part of Build 2013 was the introduction of APIs that would allow Windows Store applications to work with scanners.

The scanning APIs are located in the Windows.Devices.Scanners namespace. The scanning APIs are built on top of native Windows Image Acquisition (WIA) APIs. Only scanners that are installed with WIA drivers can be used through the scanning APIs.

To build support for scanning in a Windows Store application, you need to list all available scanners by retrieving all devices with a DeviceClass type of ImageScanner.

Hands On

Let us build a simple Windows Store application that works with scanners.

Create a new Windows Store application in the Visual Studio 2013 Express Preview for Windows, titled Windows8.1ScanningDemo.

New Project
New Project

Next, on MainPage.xaml, add two buttons titled “Get Scanner” and “Start Scanning”.

Open the code behind for MainPage.xaml.cs, and include the namespace for Scanners: Windows.Devices.Scanners

using Windows.Devices.Scanners;

Now, we will add an instance ImageScanner as a class variable.

public sealed partial class MainPage : Page
        ImageScanner myImageScanner;
        public MainPage()

We will now retrieve a scanner object. Note that only scanners with a WIA driver can be accessed with the APIs.

Next we will implement the event handler for the click event for the “Get Scanner” button.

For the click event handler, we will retrieve the device selector string for scanners.

Then, we will list all devices that match the device selector. If there is more than one device, we will list the first scanner, else we will report that no devices are present.

private async void buttonGetScannerObject_Click(object sender, RoutedEventArgs e)
            string deviceSelector = ImageScanner.GetDeviceSelector();
            var deviceInfoCollection =await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(deviceSelector, null);
            if (deviceInfoCollection.Count != 0)
                myImageScanner = await ImageScanner.FromIdAsync(deviceInfoCollection[0].Id);
                Windows.UI.Popups.MessageDialog md = new Windows.UI.Popups.MessageDialog("No scanners found")
                await md.ShowAsync();

Next, we will implement the event handler, which will actually scan and store the scanned image as part of the click event for “Start scanning” button.

For this example, we will store the image in the Pictures library.

private async void buttonStartScanning_Click(object sender, RoutedEventArgs e)
            Windows.Storage.StorageFolder sf = Windows.Storage.KnownFolders.PicturesLibrary;
            var result = await myImageScanner.ScanFilesToFolderAsync(ImageScannerScanSource.Default, sf);

If you want to build the functionality to stop scanning while in progress, you can use a CancellationTokenSource class in your application. The logic is to get a token instance when you start scanning, and when cancelation of scanning is invoked, you can call the Cancel() property on the token instance.

You can now build and compile the application. To test the application, you will need a scanner connected to the Windows 8.1 device on which you want to run the application. If you have trouble following along, you can download a sample of the code below.


In this article, we learned how to build a simple Windows Store application that can work with scanners. To keep the topic simple, we used the system defaults. Readers are encouraged to try out the other combinations of the APIs to test advanced scenarios.

About the author

Vipul Patel is a Program Manager currently working at Amazon Corporation. He has formerly worked at Microsoft in the Lync team and in the .NET team (in the Base Class libraries and the Debugging and Profiling team). He can be reached at

Related Articles



  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Anthony Christie, the Chief Marketing Officer for Level Communications, is responsible for customer experience, worldwide marketing and product management. In this informative asset, he shares his insights into why a private network connection to cloud-bases applications is the right decision for your enterprise. Download now to find out more.

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date