using System.Windows;
using System.Windows.Media.Imaging;
using Microsoft.Phone.Controls;

namespace WPCameraCaptureTask
{
    public partial class MainPage : PhoneApplicationPage
    {
        Microsoft.Phone.Tasks.CameraCaptureTask g_myCameraCaptureTask = new Microsoft.Phone.Tasks.CameraCaptureTask();
        private BitmapImage bitmapImage = new BitmapImage();

        // Constructor
        public MainPage()
        {
            InitializeComponent();
            g_myCameraCaptureTask.Completed += g_myCameraCaptureTask_Completed;
        }

        void g_myCameraCaptureTask_Completed(object sender, Microsoft.Phone.Tasks.PhotoResult e)
        {
            if (e.TaskResult == Microsoft.Phone.Tasks.TaskResult.OK)
            {
                MessageBox.Show("Bild erhalten!");
                //Bild in ein Bildobjekt laden
                bitmapImage.SetSource(e.ChosenPhoto);
                //Bildobjekt dem anzeigenden Steuerelement zuweisen
                imageResult.Source = bitmapImage;
            }
            else if (e.TaskResult == Microsoft.Phone.Tasks.TaskResult.Cancel)
                MessageBox.Show("Benutzerabbruch");
            else
                MessageBox.Show("Fehler: " + e.Error.Message);
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            g_myCameraCaptureTask.Show();
        }
    }
}