Retrieving file contents from the WinRT Camera Capture user interface

I am trying to get compressed JPEG data from the Capture Capture user interface, but I worked around IInputBuffer. Here is what I have:

private async void OnWebcamButton(object sender, RoutedEventArgs e) { var captureUi = new CameraCaptureUI(); var result = await captureUi.CaptureFileAsync(CameraCaptureUIMode.Photo); var file = await result.OpenForReadAsync(); var reader = new DataReader(file); byte[] data = new byte[reader.UnconsumedBufferLength]; await reader.LoadAsync(reader.UnconsumedBufferLength); reader.ReadBytes(data); // XXX: This is always zero Debug.Text = String.Format("Buffer is {0} bytes", data.Length); } 

Any ideas what I'm doing wrong?

+4
source share
1 answer

I don't think you need a DataReader here at all. Try the following:

 using System.Runtime.InteropServices.WindowsRuntime; // for AsBuffer() ... var file = await captureUi.CaptureFileAsync(CameraCaptureUIMode.Photo); var stream = await result.OpenForReadAsync(); byte[] data = new byte[file.Size]; await stream.ReadAsync(data.AsBuffer(), (uint)data.Length, InputStreamOptions.None); 

Alternatively, you can use the AsStream() extension method (from System.IO.WindowsRuntimeStreamExtensons ) to wrap WinRT IInputStream as System.IO.Stream , and then use regular .NET methods.

+6
source

All Articles