usage sample?

Dec 20, 2010 at 1:25 AM

I'm interested in using and perhaps contributing to this code.

It compiles fine but I'm having trouble guessing at the correct usage.  Can you post a sample?

Thanks,

Rob.

Dec 24, 2010 at 8:57 AM

Hi, I see an 'add documentation and code samples' under TODO on the home page. Eagerly awaiting these :) I want to be able to use this library rather than have my users enter the UPC manually.

Coordinator
Dec 27, 2010 at 8:36 PM

Sorry, I've been busy with the holiday and trying to release another version of PhraseMeme Scanner. 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 delegate. 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.

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

 

 

Dec 28, 2010 at 2:28 AM

Hi, I tried to follow your steps, but am blocked at creating the delegate. My knowledge of delegates is limited, so please bear with me. I tried to create a global var as:

public Action<WP7_Barcode_Library.WP7Code.BarcodeCaptureResult> done = new Action<WP7_Barcode_Library.WP7Code.BarcodeCaptureResult>

The constructor expects an object and a method.  I assume the method is the one I want executed after processing is complete, but what object do I refer it to?

 

Coordinator
Dec 28, 2010 at 9:48 PM

Sorry for the confusion. Here's some sample code:

/// <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
	{
		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);
	}
}

Coordinator
Jan 19, 2011 at 6:47 AM

I just updated the source code with a new version that includes a full sample app. Give that a try and open up a new thread if you have any more issues.