Showing posts with label ZXing. Show all posts
Showing posts with label ZXing. Show all posts

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

Sunday, 1 August 2010

WP7 ZXing Barcode

First of all I want to express my regret that I am not one of the 3.000 developers that received a WP 7 developer device (I read somewhere that there are more than 3.000 users that use Facebook from WP7). I really hoped to have a "real" device, but that's the way the cookie crumbles...
This weekend I had two days of WP 7 fun. What I've wanted to see was the use of ZXing in WP 7. There is already a C# port of the library in the ZXing trunk. Porting it to Silverlight it is quite simple (just have to replace ArrayList with generics lists and HashTable with Dictionary) more details here. So I've downloaded the latest csharp source code from ZXing trunk and compiled the library. This was the simple part because I wanted a "nice" test project. I've used the test images from the ZXing source zip as embedded resources and the gesture recognizer from Clarity Consulting this way the user is able to flick both direction between the test images. It was a project based learning because I've used MVVM and the application was following the pattern till I've ruined it with the CameraCaptureTask and PhotoChooserTask (I was not able to get them in the View Model because I don't receive the notification after I choose/capture a photo but if anyone of you can do it please enlighten me how it's done )

I cannot test CameraCaptureTask and PhotoChooserTask but maybe some of you, lucky enough to have a test device, can test it and let me know how/if it works (even in the beta dev tools the camera is poorly integrated with the apps - you will have to run again the app after selecting camera or photo and you should be able to see the selected photo in the central image of my app this way you can press the Decode button).

This is how the test project looks (don't forget to flick the image)


Here is the source code

Have a look also at this new post

NAMASTE