[UPDATE: for latest code to build your Windows 8 app with a QR Code reader, please have a look here]
I have been looking around the web for reading a QR Code from the camera of their Windows 8 device.
No luck I found nothing that was looking in that direction.
So I just take the ZXing barcode scanning library from Codeplex, modified it a bit, but the biggest part was around getting the output of the webcam as stream to get frames from it and send it over to this barcode library.
First problem, Windows 8 doesn’t support getting frames out of Video stream from managed code.
I am not really in the mood of writing C++ right now, so I just used the MediaCapture.CapturePhotoToStreamAsync method to get periodically the image from the webcam and send it over to the QRCodeReader.
Second problem, the stream received by the CapturePhotoToStreamAsync method is a BMP format in my case, and Windows 8 doesn’t expose a lot of ways to manipulate bits within the image, especially in the case I need luminance from the BMP ARGB format.
I ended up skipping the first 54 bytes of the stream (BMP header bytes) and then reading against all values to create a luminance byte array to give to the QRDecoder (that only work with luminance actually).
The last trick I tried to sue was to display a preview video stream on the screen while getting images from the photo stream, but even though Windows 8 doesn’t crash when creating, initializing and reading from multiple MediaCapture objects, it actually doesn’t display anything on the video stream part.
At the end the solution I am sharing here is displaying the same image used for scanning he barcode, which explain quite some latency between displays.
Feel free to use it and to share it for optimizing it a little bit 🙂
UPDATE: I just completely rewrote the code in a more WinRT (async await) way, which gives the app far more responsive for scanning QR Codes!!
Code sample here.