Right now your best bet is to download the latest version of the full source code (here, see link on right) and start poking around in the WP7Code folder starting with the WP7Manager.cs class. You basically set WP7BarcodeManager.ScanMode to your desired scan type and then call ScanBarcode with a callback method. There are three overrides of the ScanBarcode method, one uses the CameraCaptureTask task, one gets the image from a URI (stored content or resource in ZAP file), and one takes a BitmapImage. This lets you support a variety situations, mainly because the emulator doesn't have access to the camera so you need to use pre-generated images for testing.
The BarcodePhotoChooser.xaml and BarcodeSampleItemManger.cs classes can be used to implement a sample image chooser. It uses an XML file called SampleImages.xml located in the parent project (IE, the actual application not the library) to configure the images used as samples. These images should also be stored as content files in the parent project.
The current release is pretty bare, but I hope to clean things up and add a sample app with more documentation in the near future. I already fixed a few bugs and will be doing some re-factoring to get things into a more usable state.
Here is sample code for scanning barcodes:
/// <summary> /// Button click handler to initiate scanning. This should be ted to the click event for a button in your application /// </summary> private void ApplicationBarIconCaptureButton_Click(object sender, EventArgs e) { try { WP7BarcodeManager.ScanMode = com.google.zxing.BarcodeFormat.UPC_EAN;
if (bBypassCamera == true) //Use Barcode Sample Chooser "Task" if bypass camera setting is active (Emulator/demo mode) { NavigationService.Navigating += new NavigatingCancelEventHandler(NavigationService_Navigating); NavigationService.Navigate(BarcodeSampleItemManager.BarcodeChooserURI); //Navigate to barcode chooser page located in WP7_Barcode_Library.WP7Code } else //Use BarcodeManager to start camera and scan image { WP7BarcodeManager.ScanBarcode(BarcodeResults_Finished); //Provide callback method } } catch (Exception ex) { Debug.WriteLine("Error processing image.", ex); } } /// <summary> /// Callback method that processes results returned by the WP7BarcodeManager. Results are also stored at WP7BarcodeManager.LastCaptureResults. /// </summary> /// <param name="BCResults">Object that holds all the results of processing the barcode. Results are also stored at WP7BarcodeManager.LastCaptureResults.</param> public void BarcodeResults_Finished(BarcodeCaptureResult BCResults) { try { if (WP7BarcodeManager.LastCaptureResults.BarcodeImage != null) { imgCapture.Source = WP7BarcodeManager.LastCaptureResults.BarcodeImage; //Display image } else { //No image captured } if (BCResults.Result == BarcodeResult.Success) { txtResult.Text = BCResults.BarcodeText; //Use results } else { Debug.WriteLine(BCResults.ErrorMessage); } } catch (Exception ex) { Debug.WriteLine(String.Format("Barcode Processing Error: {0}", ex.Message)); } } //Extra code required only if you are bypassing the camera private void NavigationService_Navigating(object sender, NavigatingCancelEventArgs e) { if (e.NavigationMode == NavigationMode.Back && NavigationService.CurrentSource == BarcodeSampleItemManager.BarcodeChooserURI) { NavigationContext.QueryString["LOADSAMPLE"] = "TRUE";//Set flag to load sample } else { NavigationContext.QueryString.Remove("LOADSAMPLE"); } } private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { //Detect if page is navigating back from BarcodeSampleChooser and start processing try { string strFlag; if (NavigationContext.QueryString.TryGetValue("LOADSAMPLE", out strFlag)) { if (BarcodeSampleItemManager.SelectedItem != null) { WP7BarcodeManager.ScanBarcode(BarcodeSampleItemManager.SelectedItem.FileURI, new Action<BarcodeCaptureResult>(this.BarcodeResults_Finished)); } else { MessageBox.Show("Error: Sample chooser canceled"); } NavigationContext.QueryString.Remove("LOADSAMPLE"); } } catch (Exception ex) { Debug.WriteLine("Error processing sample image.", ex); } }