One of the features of an App I’m working on allows users to select a Photo from their WP7 Phone using PhotoChooser and upload it a service on the web. The approach I’m taking is fairly simple:
- Select photo.
- Hook event indicating photo selection occurred.
- Convert photo to byte[].
Note: This is simply proof of concept. There are likely other approaches to achieve the same result.
Add a page scope PhotoChooserTask to MainPage.xaml.cs.
Initialize the object and set up the Event Handler in the Constructor:
Add a button to your silverlight page that’ll launch the PhotoPicker when clicked.
Once an image is selected the Completed Event fires, the Photo then can be accessed. In my particular case I wanted to convert the image to a byte[] array so it could be shipped off to a web service. I can now pass bytes to my web service.
For about an hour I thought I had a bug. While debugging/deploying I’d set my Debug Target set to Windows Phone 7 Device, then launch Zune and Debug (F5) . The App deploys very quickly to WP7 but PhotoResult.TaskResult continually returned “Cancelled” after selecting a Photo from the PhotoPicker.
No matter what I did, I was unable to get the PhotoPciker to launch. Until I tried this:
- Deployed App to Device.
- Unplugged the Cable between Computer and Phone.
- Run your App.
- Success!
The PhotoPicker Completed Event is never going to fire with the Cable plugged in. I don’t know if this is an issue with the Phone or Zune.