예제 #1
0
        private Result DetectBarcode(int width, int height)
        {
            var start      = DateTime.Now;
            int bufferSize = width * height;

            #region Reader Switch Hack
            IBarcodeReader reader;
            if (_readerSwitchCount == 0)
            {
                _readerSwitchCount = DefaultReaderSwitchCount;
                reader             = _barcodeReader;
            }
            else
            {
                _readerSwitchCount--;
                reader = _qrcodeReader;
            }
            #endregion // Reader Switch Hack

            byte[] buffer = new byte[bufferSize];
            _device.GetPreviewBufferY(buffer);

            var    decodeStart = DateTime.Now;
            Result result      = reader.Decode(buffer, width, height, RGBLuminanceSource.BitmapFormat.Gray8);

            var span  = DateTime.Now - decodeStart;
            var total = DateTime.Now - start;
            //Debug.WriteLine("Barcode Decoded: " + span.TotalMilliseconds + "\tTotal: " + total.TotalMilliseconds);

            return(result);
        }
예제 #2
0
        private async Task <Result> DetectBarcodeAsync()
        {
            var width  = (int)PreviewResolution.Width;
            var height = (int)PreviewResolution.Height;

            var             rotation        = PhotoCaptureDevice.SensorRotationInDegrees;
            LuminanceSource luminanceSource = null;

            PhotoCaptureDevice.GetPreviewBufferY(_previewBuffer);

            luminanceSource = new RGBLuminanceSource(_previewBuffer, width, height, RGBLuminanceSource.BitmapFormat.Gray8);
            var result = _barcodeReader.Decode(luminanceSource);

            if (result == null)
            {
                // ok, one try with rotation by 90 degrees
                if ((Orientation & PageOrientation.Portrait) == PageOrientation.Portrait)
                {
                    // if we are in potrait orientation it's better to rotate clockwise
                    // to get it in the right direction
                    luminanceSource = new RGBLuminanceSource(RotateClockwise(_previewBuffer, width, height), height, width, RGBLuminanceSource.BitmapFormat.Gray8);
                }
                else
                {
                    // in landscape we try counter clockwise until we know it better
                    luminanceSource = luminanceSource.rotateCounterClockwise();
                }
                result = _barcodeReader.Decode(luminanceSource);
            }
            return(result);
        }
예제 #3
0
        private Result DetectBarcodeAsync()
        {
            var width         = (int)resolution.Width;
            var height        = (int)resolution.Height;
            var previewBuffer = new byte[width * height];

            device.GetPreviewBufferY(previewBuffer);

            var barcodeReader = new BarcodeReader();

            barcodeReader.Options.TryHarder = true;
            //barcodeReader.TryInverted = true;
            //barcodeReader.AutoRotate = true;

            var result = barcodeReader.Decode(previewBuffer, width, height, RGBLuminanceSource.BitmapFormat.Gray8);

            return(result);
        }