Saturday, 25 December 2010

WP7 Barcode Scanning using ZXing and Microsoft.Phone.Media.Extended

     When I first saw this blog post from Kevin Marshall it crossed my mind that it could be used for barcode scanning in order to get the same user experience you have on Android and iPhone. I've contacted Kevin to give me some details/source code for the project and a few days ago he sent me his project that is already posted on his blog here. Kevin also thought of the possibility to use it for barcode scanning, but his sample works only with QR codes. Looking at the project I saw that he was using VideoCamera class that has no Focus capability needed to take a "clean" picture of the barcode. The PhotoCamera class, on the other hand, has Focus  implemented so I simply changed the class from VideoCamera to Photocamera. In the Grab method I call the Focus method and then using the AutoFocusCompleted event I decode the barcode. For decoding I use my ZXing port. The results are pretty good as you can see in this video I've uploaded to YouTube. There are some optimizations that can be done like cropping the WritableBitmap at the dimensions of the red rectangle, but even with the full image (640x480) the speed was acceptable on my LG Optimus 7 .
     The source code and the xap of the app (that you can deploy if you have a developer/unlocked phone) are included in my latest release of the ZXing port available on CodePlex. To compile the source you will need to follow the steps Kevin indicated in this post and also you will find some hints/files here. If you start a new project you will also need to add   "ID_CAP_CAMERA" capability to WMAppManifest.xml. This, for the moment, is a hack and I don't think the application will pass Microsoft certification, but you can try. 
  "Reflecting" Microsoft.Phone.Media.Extended I saw no reason why Microsoft won't give access to developers to this assembly (put it in the SDK)! Why limit developers to do great apps when this is the first thing Microsoft needs for the Windows Phone Platform? 
     Special thanks to Kevin for the source code.


NAMASTE

0 comments:

Post a Comment