0

我按照这里的例子:http: //msdn.microsoft.com/en-us/library/windowsphone/develop/jj662940%28v=vs.105%29.aspx

我进行了实时预览和其他工作,但我怎样才能拍照?这是我尝试过的:

private PhotoCaptureDevice _photoCaptureDevice = null;
string strImageName = "IG_Temp";
private NokiaImagingSDKEffects _cameraEffect = null;
private MediaElement _mediaElement = null;
private CameraStreamSource _cameraStreamSource = null;
private Semaphore _cameraSemaphore = new Semaphore(1, 1);
MediaLibrary library = new MediaLibrary();

private async void ShutterButton_Click(object sender, RoutedEventArgs e)
{
    if (_cameraSemaphore.WaitOne(100))
    {
        await _photoCaptureDevice.FocusAsync();

        _cameraSemaphore.Release();

        CameraCaptureSequence seq = _photoCaptureDevice.CreateCaptureSequence(1);
        await seq.StartCaptureAsync();

        MemoryStream captureStream1 = new MemoryStream();

        // Assign the capture stream.
        seq.Frames[0].CaptureStream = captureStream1.AsOutputStream();

        try
        {
            // Set the position of the stream back to start
            captureStream1.Seek(0, SeekOrigin.Begin);

            // Save photo as JPEG to the local folder.
            using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream targetStream = isStore.OpenFile(strImageName, FileMode.Create, FileAccess.Write))
                {
                    // Initialize the buffer for 4KB disk pages.
                    byte[] readBuffer = new byte[4096];
                    int bytesRead = -1;

                    // Copy the image to the local folder. 
                    while ((bytesRead = captureStream1.Read(readBuffer, 0, readBuffer.Length)) > 0)
                    {
                        targetStream.Write(readBuffer, 0, bytesRead);
                    }
                }
            }
        }
        finally
        {
            // Close image stream
            captureStream1.Close();
        }

        // Navigate to the next page
        Dispatcher.BeginInvoke(() =>
        {
            NavigationService.Navigate(new Uri("/Edit.xaml?name=" + strImageName, UriKind.Relative));
        });
    }
}

但我会得到一个错误:

System.InvalidOperationException

排队:await seq.StartCaptureAsync();

我究竟做错了什么?

4

0 回答 0