コード例 #1
0
            public void OnPreviewFrame(byte [] bytes, Camera camera)
            {
                try {
                    var luminance = new YUVLuminanceSource((sbyte[])(Array)bytes, width, height, 0, 0, width, height);
                    var binarized = new BinaryBitmap(new HybridBinarizer(luminance));
                    var result    = reader.decodeWithState(binarized);

                    // an exception would be thrown before this point if the QR code was not detected

                    if (string.IsNullOrEmpty(result.Text))
                    {
                        return;
                    }

                    //ShutdownCamera ();

                    activity.OnQrScan(result);
                } catch (ReaderException) {
                    // ignore this exception; it happens every time there is a failed scan
                } catch (Exception e) {
                    // TODO: this one is unexpected.. log or otherwise handle it

                    throw;
                }
            }
コード例 #2
0
        public void OnPreviewFrame(byte [] bytes, Android.Hardware.Camera camera)
        {
            try {
                byte[] rotatedData = new byte[bytes.Length];
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        rotatedData[x * height + height - y - 1] = bytes[x + y * width];
                    }
                }

                var dataRect = GetFramingRectInPreview();

                var luminance = new YUVLuminanceSource((sbyte[])(Array)rotatedData, width, height, dataRect.Left, dataRect.Top, dataRect.Width(), dataRect.Height());
                var binarized = new BinaryBitmap(new HybridBinarizer(luminance));
                var result    = reader.decodeWithState(binarized);

                //drawResultPoints(binarized, result);

                // an exception would be thrown before this point if the QR code was not detected

                if (string.IsNullOrEmpty(result.Text))
                {
                    return;
                }

                Android.Util.Log.Debug("AEGISSHIELD", "Barcode Found: " + result.Text);
                //ShutdownCamera ();

                ShutdownCamera();

                activity.OnScan(result);
            } catch (ReaderException) {
                Android.Util.Log.Debug("AEGISSHIELD", "No barcode Found");
                // ignore this exception; it happens every time there is a failed scan
            } catch (Exception) {
                // TODO: this one is unexpected.. log or otherwise handle it

                throw;
            }
        }