4

我正在尝试从 Camera Capture UI 中获取压缩的 JPEG 数据,但我在 IInputBuffer 周围被绊倒了。这是我所拥有的:

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

任何想法我做错了什么?

4

1 回答 1

6

我认为你根本不需要DataReader这里。尝试这个:

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

或者,您可以使用AsStream()扩展方法 (from System.IO.WindowsRuntimeStreamExtensons) 将 WinRT 包装IInputStreamSystem.IO.Stream,然后使用普通的 .NET 技术。

于 2011-09-18T23:53:10.983 回答