TCD.Device

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 Winking smile)

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

QRsampleApp

Thanks to Benjamin Soulier for porting the ZXing library to WinRT!

13 thoughts on “TCD.Device

  1. 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.

  2. 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’.

  3. 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! :)

  4. 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 !

    • 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..

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>