【问题标题】:When is taking a photo done?什么时候完成拍照?
【发布时间】:2014-03-12 07:39:53
【问题描述】:

我正在开发一个 wp8 应用程序,该应用程序会拍照,然后将您带到下一个屏幕以决定您是否喜欢它。 目前的做法是这样的:

private void ShutterButton_Click(object sender, RoutedEventArgs e)
{
    if (cam != null)
    {
        try
        {
            cam.CaptureImage();

            await Task.Delay(1500);
            NavigateFront();
        }
        catch (Exception ex)
        {
            ...
        }
    }
}

public void NavigateFront()
{
    string naviString = "/confirmPicture.xaml?parameter=" + fileName.ToString();   
    _rootFrame.Navigate(new Uri(naviString, UriKind.Relative));
}

在我的 Lumia 520 上,它有时会崩溃。如果我将等待时间增加到 2.5 秒,它会起作用。但当然这不应该是这样做的方式。

如果我捕捉到void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)-Event 并在一切完成并且所有流都关闭后尝试导航,我仍然会进入NavigateFailed-状态并且应用程序崩溃。

我的问题是:是否有任何其他有用的事件可以确保完成所有工作并且我可以在不使用基于时间的静态值的情况下进行导航?

【问题讨论】:

标签: c# events windows-phone-8 photo navigateuri


【解决方案1】:

可以使用 PhotoCamera 进行导航,只需订阅其 CaptureCompleted 事件处理程序

cam.CaptureCompleted += new EventHandler<CameraOperationCompletedEventArgs>(camera_CaptureCompleted);

这就是事件

    void camera_CaptureCompleted(object sender, CameraOperationCompletedEventArgs e)
    {
        try
        {
            Deployment.Current.Dispatcher.BeginInvoke(delegate()
            {
                try
                {
                    cam.Dispose();
                    NavigationService.Navigate(new Uri("URI nething", UriKind.Relative));
                }
                catch (Exception)
                {

                     MessageBox.Show("Problem occured!!");
                }

            });
        }
        catch
        {
            MessageBox.Show("Problem in camer_capturecompleted");
        }
    }

我在我的一个针对 windows phone 7 的应用程序中做到了。检查这是否也适合你。

【讨论】:

  • 大声笑,谢谢!我使用了cam_CaptureImageAvailable,因为在msdn 上它说它与cam_CaptureCompleted 相同,外加等待图像。不,我使用带有图像的图像来存储它并完成捕获以进行导航。没有计时器。谢谢! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-22
  • 2017-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多