2011-04-01 12 views
6

Görüntüyü telefondan almak ve değiştirmek için WP7'de CameraCaptureTask kullanmak istiyorum. Benim kodudur:WP7 üzerinde CameraCaptureTask

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; 
     } 
    } 

} 

sorun her zaman i button1 tıklayın olduğu, olay ortaya ama değeri OK TaskResult.Cancel instad olduğunu. Dahası, telefonda kamera gösterilmiyor.

Herhangi bir fikrin var mı? Teşekkürler

+0

olası yinelenen [Windows Phone 7 - CameraTask, Çalışmayan] (http://stackoverflow.com/questions/4891115/windows-phone-7 -cameratask-not-working) –

cevap

14

Hata ayıklayıcı ekli çalışıyor mu? Eğer öyleyse, Zune yazılımını kullanarak cihaza bağlandığınızda kamera çalışmaz.

WPConnect aracını kullanarak bağlarsanız, o zaman çalışmalıdır.

+0

Evet sorun buydu. Zune ile cihaza bağlandım. – user422688

+0

Bu çok güzel, Microsoft'un neden belgeleri kaldırdığını bilmiyorum. –

0

Bunu deneyin.

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; 
    } 

} 
1

Bu deneyebilirsiniz ...

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; 
     } 
    } 
ait