CameraCaptureTask on WP7

I want to use CameraCaptureTask on WP7 to get the image from the phone and manipulate it. My code is:

CameraCaptureTask cameraCaptureTask; public MainPage() { InitializeComponent(); try { cameraCaptureTask = new CameraCaptureTask(); cameraCaptureTask.Completed += new EventHandler<PhotoResult>(cameraCaptureTask_Completed); } catch (System.InvalidOperationException ex) { MessageBox.Show(ex.Message); } } private void button1_Click(object sender, RoutedEventArgs e) { try { cameraCaptureTask.Show(); } catch (System.InvalidOperationException ex) { MessageBox.Show(ex.Message); } } void cameraCaptureTask_Completed(object sender, PhotoResult e) { MessageBox.Show("event: " + e.TaskResult.ToString()); if (e.TaskResult == TaskResult.OK) { BitmapImage bmp = new BitmapImage(); bmp.SetSource(e.ChosenPhoto); image1.Source = bmp; } } } 

The problem is that every time I press button1, the event is raised, but the value is TaskResult.Cancel instad OK. In addition, the camera does not display on the phone.

Any idea? Thanks

+6
windows-phone-7
source share
3 answers

Do you work with a debugger application? If so, the camera will not work when you connect to the device using Zune software.

If you connect using the WPConnect tool, it should work.

+14
source share

You can try this ...

 private void button1_Click(object sender, RoutedEventArgs e) { try { cameraCaptureTask = new CameraCaptureTask(); cameraCaptureTask.Completed += new EventHandler<PhotoResult>(cameraCaptureTask_Completed); cameraCaptureTask.Show(); } catch (System.InvalidOperationException ex) { MessageBox.Show(ex.Message); } } void cameraCaptureTask_Completed(object sender, PhotoResult e) { MessageBox.Show("event: " + e.TaskResult.ToString()); if (e.TaskResult == TaskResult.OK) { BitmapImage bmp = new BitmapImage(); bmp.SetSource(e.ChosenPhoto); image1.Source = bmp; } } 
+1
source share

Try it.

 void ctask_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK && e.ChosenPhoto != null) { //Take JPEG stream and decode into a WriteableBitmap object App.CapturedImage = PictureDecoder.DecodeJpeg(e.ChosenPhoto); //Collapse visibility on the progress bar once writeable bitmap is visible. progressBar1.Visibility = Visibility.Collapsed; //Populate image control with WriteableBitmap object. ImageMain.Source = App.CapturedImage; } } 
0
source share

All Articles