开发者

Camera Capture in WP7 Mango

I've recently upgraded my WP7 app to Mango and am having some problems with the camera. The code below used to work on 7.0, but on 7.1 the completed handler fires before the dialog is even shown, so I can't capture the result. After taking the photo, the phone displays "Resuming..." which it never used to do.

var dlg = new CameraCaptureTask();
            dlg.Completed += (s, e) =>
            {
                if (e.TaskResult == TaskResult.OK) {
                    BitmapImage bmp = new BitmapImage();
                    bmp.SetSource(e.ChosenPhoto);
                    //var img = new Image();
                    //img.Source = bmp;

                    string caption = string.Empty;
                    var inputDialog = new InputPrompt()
                    {
                        Title = "Caption",
                        Message = "Enter caption/description for snapshot",
                    };
                    inputDialog.Completed += (ss, ee) =>
                                                 {
                                                     if (ee.PopUpResult == PopUpResult.Ok)
                                                     {
                                                         caption = ee.Result;

                                                         var snap = SnapshotBLL.AddSnapshot(recipeId, bmp, caption);
                                           开发者_JAVA技巧              onComplete(null, new SnapshotEventArgs(snap));
                                                     }
                                                 };
                    inputDialog.Show();
                }
            };
            dlg.Show();

The MSDN docs appear to show a variation of my code but I can no longer get the result of the camera capture task.


Assuming that your sample comes from a single method I wouldn't expect it to ahve worked pre Mango.

The CameraCaptureTask should be created and the callback assigned in the constructor of the page for it to work properly.
Something like:

public partial class MainPage : PhoneApplicationPage
{
    private CameraCaptureTask cct = new CameraCaptureTask();

    public MainPage()
    {
        InitializeComponent();

        cct.Completed += new EventHandler<PhotoResult>(cct_Completed);
    }

    private void cct_Completed(object sender, PhotoResult e)
    {
        // Do whatever here
    }

    private void SomeEventHandler(object sender, RoutedEventArgs e)
    {
        cct.Show();
    }
}

This works in both 7.0 & 7.1

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜