2011-04-01 6 views
6

휴대 전화에서 이미지를 가져와 조작하려면 WP7에서 CameraCaptureTask를 사용하고 싶습니다. 내 코드는 다음과 같습니다WP7의 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; 
     } 
    } 

} 

문제는 때마다 내가 Button1을 클릭 것으로, 이벤트가 발생하지만 값이 OK의 TaskResult.Cancel의 instad입니다. 또한 전화기에는 카메라가 표시되지 않습니다.

아이디어가 있으십니까? 감사합니다

+0

가능한 중복 [윈도우 폰 7 - CameraTask 작동하지 않음 (http://stackoverflow.com/questions/4891115/windows-phone-7 -cameratask-not-working) –

답변

14

디버거가 연결되어 실행 중입니까? 그렇다면 Zune 소프트웨어를 사용하여 장치에 연결할 때 카메라가 작동하지 않습니다.

WPConnect 도구를 사용하여 연결하면 제대로 작동합니다.

+0

예, 문제가 있습니다. Zune을 사용하여 장치에 연결되었습니다. – user422688

+0

이것은 정말 멋지다. 왜 마이크로 소프트가 문서를 삭제했는지 모르겠다. –

0

시도해보십시오.

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

당신이 시도 할 수 있습니다 ...

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