I’m trying to get the compressed JPEG data out of the Camera Capture UI, but I’m getting tripped up around IInputBuffer. Here’s what I’ve got:
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?
I don’t think you need a
DataReaderhere at all. Try this:Alternatively, you can use
AsStream()extension method (fromSystem.IO.WindowsRuntimeStreamExtensons) to wrap WinRTIInputStreamasSystem.IO.Stream, and then use normal .NET techniques.