Windows runtime ZXing.net解码抛出IndexOutOfRangeException

Windows runtime ZXing.net解码抛出IndexOutOfRangeException,windows-runtime,windows-phone-8.1,ocr,qr-code,zxing,Windows Runtime,Windows Phone 8.1,Ocr,Qr Code,Zxing,我正在构建一个Windows Phone应用程序(使用Windows Runtime,它是一个通用应用程序),需要能够扫描二维码。我正在使用ZXing.NET。我遇到的问题如下:当相机开始拍摄时,ZXing抛出了一个IndexOutOfRangeException: A first chance exception of type 'System.IndexOutOfRangeException' occurred in ZXing.winmd at ZXing.BitmapLuminan

我正在构建一个Windows Phone应用程序(使用Windows Runtime,它是一个通用应用程序),需要能够扫描二维码。我正在使用ZXing.NET。我遇到的问题如下:当相机开始拍摄时,ZXing抛出了一个IndexOutOfRangeException:

A first chance exception of type 'System.IndexOutOfRangeException' occurred in ZXing.winmd
   at ZXing.BitmapLuminanceSource..ctor(WriteableBitmap writeableBitmap)
   at ZXing.BarcodeReader.<.cctor>b__4(WriteableBitmap bitmap)
   at ZXing.BarcodeReader.Decode(WriteableBitmap barcodeBitmap)
   at xxx.Views.Scanner2.ScanBitmap(WriteableBitmap writeableBmp)
   at xxx.Views.Scanner2.<OnNavigatedTo>d__5.MoveNext()
ScanBitmap函数如下所示:

private Result ScanBitmap(WriteableBitmap writeableBmp)
{
    var barcodeReader = new BarcodeReader
    {
        Options = new DecodingOptions
        {
            PossibleFormats = new[] { BarcodeFormat.QR_CODE },
            TryHarder = true
        },
        AutoRotate = true
    };
    var result = barcodeReader.Decode(writeableBmp);

    if (result != null)
    {
        CaptureImage.Source = writeableBmp;
    }

    return result;
}
完整的源代码可以在这里找到:

当我将图像捕获到文件系统,然后读取它(而不是将图像捕获到内存流)时,我没有这个问题,但这非常慢,会使用户界面在几秒钟内完全没有响应。访问相册还需要不必要的权限


有人知道我怎样才能让它工作吗?我找到了此线程,但我不理解解决方案:。我还发现了另一个使用诺基亚图像SDK的示例,但这对我也不适用。

因此,多亏了。原来进入mediaCapture.CapturePhotoToStreamAsync的
图像编码属性
需要一个宽度和高度。我将宽度设置为400,高度设置为600。我还为
WriteableBitmap
使用了相同的宽度+高度。它现在工作得很好!(尽管仍然有点慢)

因此,多亏了。原来进入mediaCapture.CapturePhotoToStreamAsync的
图像编码属性
需要一个宽度和高度。我将宽度设置为400,高度设置为600。我还为
WriteableBitmap
使用了相同的宽度+高度。它现在工作得很好!(虽然还是有点慢)

private Result ScanBitmap(WriteableBitmap writeableBmp)
{
    var barcodeReader = new BarcodeReader
    {
        Options = new DecodingOptions
        {
            PossibleFormats = new[] { BarcodeFormat.QR_CODE },
            TryHarder = true
        },
        AutoRotate = true
    };
    var result = barcodeReader.Decode(writeableBmp);

    if (result != null)
    {
        CaptureImage.Source = writeableBmp;
    }

    return result;
}