Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CameraCaptureTask on WP7

I want to use CameraCaptureTask on WP7 in order to get image from 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 click button1, the event is raised but the value is TaskResult.Cancel instad of OK. Moreover, in the phone the camera is not shown.

Any idea? Thanks

like image 993
user422688 Avatar asked Apr 01 '11 09:04

user422688


2 Answers

Are you running with the Debugger attached? If so, the camera will not work when you connect to the device using the Zune software.

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

like image 135
Damian Avatar answered Oct 17 '22 05:10

Damian


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;
        }
    }
like image 30
Archana Avatar answered Oct 17 '22 04:10

Archana