Just another TCD namespace: TCD.Device. Its purpose is to contain additional namespaces that use features like Camera, GPS, Accelerometer, Compass.. Everything that has an effect on the App permissions the user sees on the Windows Phone or Windows 8 application. (Like ‘This app has access to your location, compass..’)
TCD.Device.Camera
CodeScannerPopup is another async control, specific to the Windows Phone platform, that can be used to scan for QR codes. (In theory other 2D-codes as well.)
Usage:
- add the TCD.Device.Camera NuGet package
- add using directives for TCD.Device.Camera and TCD.Device.Camera.Barcodes
- in the calling method (eg. a Button.Click event)
- hide/show ApplicationBar, attach/remove BackKeyPress event
Code sample:
private async void Button_Click(object sender, RoutedEventArgs e)
{
CodeScannerPopup scp = new CodeScannerPopup(Microsoft.Phone.Shell.SystemTray.IsVisible, Format.ALL_1D);
//important: hide ApplicationBar and handle BackKeyPress
ApplicationBar.IsVisible = false;
this.BackKeyPress += scp.HandleBackKeyPress;
//now let’s go
ScanResult r = await scp.ShowAsync(“BARCODE SCANNER”, “scan”);
if (r != null)
output.Text = string.Format(“{0}n{1}”, r.Text, r.Format.ToString());
//clean up
this.BackKeyPress -= scp.HandleBackKeyPress;
ApplicationBar.IsVisible = true;
}
And finally: The BarcodeScannerSample application.
TCD.Device.Camera.Barcodes.Encoder is available on Windows 8 and provides a method to generate QR codes (in form of a BitmapSource) from a string.
myImage.Source = await Encoder.GenerateQRCodeAsync(“some string”, 300);
That’s right, one line! (Don’t forget to add the NuGet package first )
I forgot the IntelliSense contents, but instead I have a nice pic of my cat the sample app for you:
EDIT: New sample app on MSDN: http://code.msdn.microsoft.com/Generate-QR-Codes-on-cdac562f
Thanks to Benjamin Soulier for porting the ZXing library to WinRT!
kishore
How to decode qrcode image ?
thecake
I have not yet succeeded to decoe QR codes in Windows 8 – take a look at this: http://www.soulier.ch/?p=1275&lang=en
kishore
I already tried Benjamin’s code but not working………………..
Hocine
I keep guetting ‘IndexOutOfBound exception’ on the line com.google.zxing.LuminanceSource source = new RGBLuminanceSource(myPicArray, bitmapImage.DecodePixelWidth,
bitmapImage.DecodePixelHeight);
no matter what values i put in.
thecake
In what file does this exception occur? (I can’t find the line in my sources..) You refer to the Windows Phone implementation, right?
From the type of the exception, I would guess, that ‘myPicArray’ does not have the same number as pixels as ‘bitmapImage’.
Nirmit Kavaiya
Hi,
I’d like to inform you that the ZXing WinRT is in debug build which is failing the Windows App Certification Kit, and will also fail Store certification.
Can you please update the NuGet with release build?
Thank you for the code! 🙂
thecake
Oh, thanks!
I’ll update the package as soon as I’m on my machine! ETA 3 hours.
Sorry for the inconvenience 😉
Nirmit Kavaiya
No problem! 🙂
thecake
The new version is online now.
I’ve made a new sample and uploaded to MSDN: http://code.msdn.microsoft.com/Generate-QR-Codes-on-cdac562f
Just to make sure, I ran the App Cert Kit on it – everything seems fine now =)
idepixgames
Hi, I’m trying to use your library (this is for my Videobrary app) but it seems it needs the AsyncCtpLibrary.
Could you update it so that it uses the latest and greatest Microsoft.Bcl.Async NuGet package ?
I can’t use it because of that.
Thanks a lot !
thecake
yes, of course!
I’ll do that as soon as possible!
thecake
This morning I updated the NuGet package – it’s a prerelease version now, because it depends on Microsoft.Bcl.Async, which is only available as a prerelease package.. (you have to change the NuGet Package Manager setting accordingly..)
I suggest you to set up the Camera yourself, subscribe to the OnNewPreviewFrame (or something like that) event and each time kick Decoder.Decode() asynchronously..
idepixgames
Thanks for the fast update ! I’ll try that when I get home 🙂