2

I'm trying to create an app that can use the camera for Windows Phone 8.1, using the Windows RT/XAML development model.

When I try to call either of the capture methods off of the MediaCapture class I get an ArgumentException with the message "The parameter is incorrect." Here is my code

    private async Task Initialize()
    {
        if (!DesignMode.DesignModeEnabled)
        {               
            await _mediaCaptureMgr.InitializeAsync();
            ViewFinder.Source = _mediaCaptureMgr;
            await _mediaCaptureMgr.StartPreviewAsync();
        }
    }

    private async void ViewFinder_OnTapped(object sender, TappedRoutedEventArgs e)
    {
        ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();

        var stream = new InMemoryRandomAccessStream();

        await _mediaCaptureMgr.CapturePhotoToStreamAsync(imageProperties, stream);

        _bitmap = new WriteableBitmap((int) ViewFinder.ActualWidth, (int) ViewFinder.ActualHeight);
        stream.Seek(0);
        await _bitmap.SetSourceAsync(stream);

        PreviewImage.Source = _bitmap;
        PreviewElements.Visibility = Visibility.Visible;
        ViewFinder.Visibility = Visibility.Collapsed;
        Buttons.Visibility = Visibility.Visible;
        Message.Visibility = Visibility.Collapsed;

        stream.Seek(0);
        var buffer = new global::Windows.Storage.Streams.Buffer((uint) stream.Size);
        stream.ReadAsync(buffer, (uint) stream.Size, InputStreamOptions.None);

        DataContext = buffer.ToArray();
        if (PhotoCaptured != null)
            PhotoCaptured(this, null);
    }

The initialize method is called on page load, and the viewfinder_ontapped is called when they tap the CaptureElement I have in the xaml. The error is thrown on

await _mediaCaptureMgr.CapturePhotoToStreamAsync(imageProperties, stream);

What's really bizarre is that I downloaded the latest source for the winrt xaml toolkit http://winrtxamltoolkit.codeplex.com/ and tried their sample camera app, which uses similar code. It throws the same error on MediaCapture.CapturePhotoToStorageFileAsync(). Can anyone help me identify why?

AndrewSwerlick
  • 913
  • 8
  • 24
  • I've just tired your code, and I couldn't reproduce the problem - can you try [to run my sample](http://1drv.ms/URElvU)? – Romasz Jun 19 '14 at 21:49
  • I've been working on a colleague with this and it looks like it may be a device issue. I'll try the sample on Monday when I have access to the phone again, if it hasn't already been factory reset. – AndrewSwerlick Jun 20 '14 at 13:44

0 Answers0