WP7 : Real-time video scan a barcode/QR code in your app using ZXing lib

Now that we can scan a barcode from a picture thanks to ZXing lib, let’s try to improve the user experience.

It would be much better to scan a barcode in real time, just like WP7 does out of the box. I wanted to provide this kind of experience in my own application. You can do the same by downloading the following lib and use the code below.

Get Microsoft Silverlight



Download the lib

Download the binaries and add a reference to both dlls in your own project.

Write the code

Use the video scan lib by calling the static StartScan method of the BarCodeManager static class.

/// <summary>
/// Starts the scan : navigates to the scan page and starts reading video stream
/// Note : Scan will auto-stop if navigation occurs
/// </summary>
/// <param name="onBarCodeFound">Delegate Action on a barcode found</param>
/// <param name="onError">Delegate Action on error</param>
/// <param name="zxingReader">(optional) A specific reader format, Default will be EAN13Reader </param>
public static void StartScan(Action<string> onBarCodeFound, Action<Exception> onError, BarcodeFormat barcodeFormat = null)

Parameters are:

- Action<string> onBarCodeFound : a delegate called on a background thread as soon as a barcode/QR code is detected. The parameter is the associated barcode/QR string 
- Action<Exception> onError : a delegate on error. The parameter is the associated exception that generated the error - BarcodeFormat barcodeFormat = null : the type of code that should be scanned (default = UPC_EAN): ALL_1D;
// Auto detect

Calling StartScan will launch the WP7 camera, and start the scanning process which consists in:

  1. start focusing
  2. once focused, try scanning during 1.5 sec

If unsuccessful, it will retry 15 times after what it will call the onError callback with a VideoScanException exception as a parameter. You can update the trial count by setting BarCodeManager.MaxTry (default is 15).

If a code was found, the onBarCodeFound callback will be called with the string code found as a parameter.



Scan a bar code

private void Button_Click(object sender, RoutedEventArgs e)
        // on success
        (b) => Dispatcher.BeginInvoke(() => 
                tbScanResultBarCode.Text = b;
        // on error
        (ex) => Dispatcher.BeginInvoke(() => 
                tbScanResultBarCode.Text = ex.Message;
        // Default : please, decode any bar-code

Scan a QR code

private void Button_Click_1(object sender, RoutedEventArgs e)
        // on success
        (b) => Dispatcher.BeginInvoke(() => 
                tbScanResultQR.Text = b;
        // on error
        (ex) => Dispatcher.BeginInvoke(() => 
                tbScanResultQR.Text = ex.Message;
        // Please, decode a QR Code

Get the source code and test the sample application

You can test the sample application ang get the whole code here.

The lib uses the video capabilities of WP7.1 SDK with the PhotoCamera class. The code is inspired from the original idea of Pierre Cauchois and includes some snippets from SLAR toolkit.

[This is an early version made for my own purpose and was not tested for production]

Comments (21)

  1. Tim says:

    Is it possible to scan a barcode in portrait mode?

  2. Hello Tim, this version only supports landscape mode

  3. reena says:


    Its urgent for me.Please help out from this.I have taken downloaded same code but every time its displaying error as (reader Exception on this statement "result = BarCodeManager.ZXingReader.decode(binaryBitmap)".I am unable to find out the error.

    Desperately waiting for your reply.

    Advance thanks.

  4. Hi reena,

    The downloaded source code should be working well.

    Can you contact me by email for further investigation ?

  5. Kevin McFarland says:

    Any attempt to create a Win7 store app?  I have interest in a home inventory app to:

    1. scan groceries for home inventory and integrate to shopping list

    2. scan equipment for insurance list

    3. up load to skydrive to export inventory

    I'm willing to Angel fund this




  6. Claude Vernier says:

    Hi, thank you for this blog.

    I have tried your code. Unfortunatly, all I have right now is the emulator…  is there a solution for that scenario ?

    Hoping to see you at the Techdays on 08 Feb 2012 à Paris 🙂

  7. John says:


    It´s possible scan a DataMatrix Barcode?

    I´m using its but not works.

    What can I do for this?



  8. Hello,

    I experienced the same problem with ReaderException as reena. Have you managed to investigate it?

    Thanks in advance.

  9. Hi all,

    At this point, the lib works well when deployed on the device. It does not support emulator mode as it need your video stream including the barcode/QR code.

    If you have any trouble with this sample/lib, it might be because:

    1 – you didn't deploy it on a device

    2 – you did not install the latest Windows Phone SDK

    I updated the source code with a warning messagebox when working on the emulator.

    If you checked the 2 points mentionned earlier, and it still doens't work, please contact me by email.


  10. Alessio says:

    is there a way to display the qr focus area on the camera screen ?

  11. kit says:

    Hi, thank you for the sample application, but in the sample, if i press back key in the scanning view, it will throw an exception, any idea to solve it??

  12. alex says:

    nice post.  It works well for your code.  However, if I want to cancel the scanning, it will crashed if I press the physical back button.  How can we avoid this??

  13. Ajaxer says:

    Many thanks for this sample project. I found it very helpful in learning how to deal with the camera and capturing a barcode automatically.

    Merci beaucoup.

  14. I've got a few QrCodes printed on paper which do work really well with the integrated bing scan&search capability of windows phone.

    Pity is, they hardly work with your sample app. It takes ages until they are recognised, and usually only after I rotate the phone a few times around, if at all.

    Is this a limitation of the zxing lib or might something in your wrapper be the problem?

  15. Mike says:

    Tt looks this example doesn't work on Windows Phone 8, any ideas?

  16. Lavz says:

    Please ,anyone help me , that WP7.videoScanZXing work on windows phone 8 ?

  17. Great post!


    I try to test it on my wp7 device but when i tap on button ("tap to scan a barcode") the app will crash.

  18. Mehwish says:

    Hi! im a beginner for Mobile App…i got your App but when i tried to deploy this app on my Windows 7 OD Lumia it show and error that the device is locked. Can anyone help me out for this bcoz i really need to test it on my device and wanted to work on it futher. reply ASAP Plz.

  19. LGB says:


    To those of you who have deployed the sample on your devices and get the following reader Exception on this statement "result = BarCodeManager.ZXingReader.decode(binaryBitmap)"

    It is because the code states that it should work with 13 bar barcodes: // Default : please, decode a 13 bar-code. (The first place I saw it was in MainPage.xaml.cs)

    I realized that otherwise it won't work.

  20. Mat says:


    Great Tut !

    I want to make an offline OCR. Is it possible to do it with this lib ?

  21. Duc says:

    Does this work on Windows phone 8 ?

Skip to main content