This project has moved and is read-only. For the latest updates, please go here.

WindowsRTDemo speed up

Nov 25, 2013 at 7:26 AM
Hi,

I am new to ZXing.Net, so that might have been discussed already, but just in case. I was looking at the code in MainPage::OnNavigatedToo() and I think StorageFile could be replaced by InMemoryRandomAccessStream() to speed up the loop. Something along those lines:
using Windows.Storage.Streams;
using Windows.Graphics.Imaging;

using (var stream = new InMemoryRandomAccessStream())
{
    await capture.CapturePhotoToStreamAsync(imageProps, stream);
    stream.Seek(0);

    var bitmapDecoder = await BitmapDecoder.CreateAsync(BitmapDecoder.BmpDecoderId, stream);

    var data = await bitmapDecoder.GetPixelDataAsync(
        BitmapPixelFormat.Bgra8,
        BitmapAlphaMode.Straight,
        new BitmapTransform(),
        ExifOrientationMode.IgnoreExifOrientation,
        ColorManagementMode.DoNotColorManage
        );

    var result = barcodeReader.Decode(
        data.DetachPixelData(),
        (int)bitmapDecoder.PixelWidth,
        (int)bitmapDecoder.PixelHeight,
        BitmapFormat.BGR32
        );
}
On a couple of machines I tried that with that gave ~200ms per frame (5fps), in less-than-ideal lighting conditions.
Dec 1, 2013 at 8:09 PM
I think you are right.
I can't test your changes at the moment because I don't have a Win8 pc with a camera.
Anyway, thanks for the information.
Oct 7, 2014 at 2:44 AM
Edited Oct 7, 2014 at 2:45 AM
I tried your suggestion but when I run Decode() I Always get a Null Object.

Here is what I tried:
try
{
    using (var stream = new InMemoryRandomAccessStream())
    {
        ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateBmp();

        await Camera.CapturePhotoToStreamAsync(imageProperties, stream);
        
        stream.Seek(0);

        var bitmapDecoder = await BitmapDecoder.CreateAsync(BitmapDecoder.BmpDecoderId, stream);

        var data = await bitmapDecoder.GetPixelDataAsync(
            BitmapPixelFormat.Bgra8,
            BitmapAlphaMode.Straight,
            new BitmapTransform(),
            ExifOrientationMode.IgnoreExifOrientation,
            ColorManagementMode.DoNotColorManage
            );

        BCReader = new BarcodeReader();
        BCReader.Options.TryHarder = true;

        var result = BCReader.Decode(
            data.DetachPixelData(),
            (int)bitmapDecoder.PixelWidth,
            (int)bitmapDecoder.PixelHeight,
            BitmapFormat.BGR32
            );

        bc.Text = result.Text;
    }
}
catch (Exception e)
{
    bc.Text = e.Message;
}