0

I followed the examples here: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662940%28v=vs.105%29.aspx

I made the live preview and stuff work, but how can I take a picture? This is what i tried:

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));
        });
    }
}

But I will get an error:

System.InvalidOperationException

in line: await seq.StartCaptureAsync();

What am I doing wrong?

David Božjak
  • 16,887
  • 18
  • 67
  • 98
4ndro1d
  • 2,926
  • 7
  • 35
  • 65
  • The message component of your exception would be helpful as well. – lsuarez Feb 28 '14 at 17:15
  • Gimme a sec. I'll update my question – 4ndro1d Feb 28 '14 at 17:17
  • Hmm okay, I don't know what you mean. There is nothing else than this line of code in my console. It will just jump to `Debugger.Break();` – 4ndro1d Feb 28 '14 at 17:19
  • Eine Ausnahme (erste Chance) des Typs "System.InvalidOperationException" ist in Imbagram.DLL aufgetreten. - german only sry – 4ndro1d Feb 28 '14 at 17:20
  • System.InvalidOperationException should usually include a "message" property that describes the actual problem. i.e. "System.InvalidOperationException: You borked all teh codez!!!1" – lsuarez Feb 28 '14 at 17:20
  • I can't find anything else :( – 4ndro1d Feb 28 '14 at 17:22
  • If you want to you can have a look at the project itself. https://www.dropbox.com/sh/fquvmm8aqiei4wz/U1cY6CgAyv – 4ndro1d Feb 28 '14 at 17:24
  • 2
    From MSDN: "Before you can start a capture with StartCaptureAsync, you must call the PrepareCaptureSequenceAsync method." – CÅdahl Feb 28 '14 at 20:25
  • Thanks! That was it. But the saved image now is nearly completely dark. :/ – 4ndro1d Feb 28 '14 at 22:19
  • Seems the filters aren't applied correctly to the saved image now. But post your comment as answer, so I can accept it – 4ndro1d Feb 28 '14 at 22:28

0 Answers0