Пример #1
0
        protected override bool ProcessFrame(MediaFrameReference frameReference)
        {
            // doc here https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.media.capture.frames.videomediaframe.aspx
            // says to dispose this softwarebitmap if you access it.
            using (var bitmap = frameReference.VideoMediaFrame.SoftwareBitmap)
            {
                try
                {
                    // I can go via this route or I can go via the IMemoryBufferByteAccess
                    // route but, either way, I seem to end up copying the bytes into
                    // another buffer which I don't really want to do :-(
                    if (this.buffer == null)
                    {
                        this.buffer = new byte[4 * bitmap.PixelHeight * bitmap.PixelWidth];
                    }
                    bitmap.CopyToBuffer(buffer.AsBuffer());

                    this.QrZxingResult = ZXingQRCodeDecoder.DecodeBufferToQRCode(
                        buffer, bitmap.PixelWidth, bitmap.PixelHeight, BitmapFormat.BGR32);
                }
                catch
                {
                }
            }
            return(this.QrZxingResult != null);
        }
        string ProcessFrame(SoftwareBitmap bitmap)
        {
            if (bitmap == null)
            {
                return(null);
            }
            try
            {
                if (this.buffer == null)
                {
                    this.buffer = new byte[4 * bitmap.PixelHeight * bitmap.PixelWidth];
                }
                bitmap.CopyToBuffer(buffer.AsBuffer());

                var zxingResult = ZXingQRCodeDecoder.DecodeBufferToQRCode(
                    buffer, bitmap.PixelWidth, bitmap.PixelHeight, BitmapFormat.BGR32);

                if (zxingResult != null)
                {
                    return(zxingResult.Text);
                }
            }
            catch
            {
            }
            return(null);
        }