Search code examples
win-universal-appqr-codezxing

QR code in Universal Windows


How correct way to preview video and recognize QR (any codes with ZXing)?

In windows phone 8.1 i start preview with MediaCapture and with VideoEffect recognize QR code.

In Universal Windows VideoEffect not work.

Recognize by timer with CapturePhotoToStorageFileAsync is slowly.


Solution

  • So, my solution

    1. Create new WinRT project "Windows Runtime Component (Universal Windows)

    2. In WinRT create

    class CaptureVideoEffect : IBasicVideoEffect (from Windows.Media.Effects)
    
    1. Attach effect to MediaCapture
    await capture.AddEffectAsync(MediaStreamType.VideoPreview, typeof(CaptureVideoEffect).FullName, ...);
    
    1. Now in CaptureVideoEffect.ProcessFrame(ProcessVideoFrameContext context) you get RealTime video output

    2. In CaptureVideoEffect.ProcessFrame skip frame if previous not finish decoded

    3. Get image as byte[]

    var frameSize = inputFrameBitmap.PixelWidth * inputFrameBitmap.PixelHeight * 4;
    var frameBuffer = new Windows.Storage.Streams.Buffer((uint)frameSize);
    inputFrameBitmap.CopyToBuffer(frameBuffer);
    byte[] bitmap = frameBuffer.ToArray();
    
    1. Decode with
    result = barcodeReader.Decode(bitmap, inputFrameBitmap.PixelWidth, inputFrameBitmap.PixelHeight, BitmapFormat.RGB32);
    
    public sealed class BarcodeReader
    {
         public Result Decode([ReadOnlyArray] byte[] rawRGB, int width, int height, BitmapFormat format);
    }