コード例 #1
0
        void InitializeAndStartBarcodeScanning()
        {
            // The scanning behavior of the barcode picker is configured through scan
            // settings. We start with empty scan settings and enable a generous set
            // of 1D symbologies. MatrixScan is currently only supported for 1D
            // symbologies, enabling 2D symbologies will result in unexpected results.
            // In your own apps, only enable the symbologies you actually need.
            ScanSettings settings = ScanSettings.Create();

            int[] symbologiesToEnable = new int[] {
                Barcode.SymbologyEan13,
                Barcode.SymbologyEan8,
                Barcode.SymbologyUpca,
                Barcode.SymbologyCode39,
                Barcode.SymbologyCode128,
                Barcode.SymbologyInterleaved2Of5,
                Barcode.SymbologyUpce
            };

            foreach (int symbology in symbologiesToEnable)
            {
                settings.SetSymbologyEnabled(symbology, true);
            }

            // Enable MatrixScan and set the max number of barcodes that can be recognized per frame
            // to some reasonable number for your use case. The max number of codes per frame does not
            // limit the number of codes that can be tracked at the same time, it only limits the
            // number of codes that can be newly recognized per frame.
            settings.MatrixScanEnabled        = true;
            settings.MaxNumberOfCodesPerFrame = 10;

            // Prefer the back-facing camera, if there is any.
            settings.CameraFacingPreference = ScanSettings.CameraFacingBack;

            barcodePicker = new BarcodePicker(this, settings);
            barcodePicker.OverlayView.SetGuiStyle(ScanOverlay.GuiStyleMatrixScan);

            // Set the GUI style to MatrixScan to see a visualization of the tracked barcodes. If you
            // would like to visualize it yourself, set it to ScanOverlay.GuiStyleNone and update your
            // visualization in the didProcess() callback.
            barcodePicker.OverlayView.SetGuiStyle(ScanOverlay.GuiStyleMatrixScan);

            // When using MatrixScan vibrating is often not desired.
            barcodePicker.OverlayView.SetVibrateEnabled(false);

            // Register listener, in order to be notified about relevant events
            // (e.g. a successfully scanned bar code).
            barcodePicker.SetOnScanListener(this);

            // Register a process frame listener to be able to reject tracked codes.
            barcodePicker.SetProcessFrameListener(this);

            // Set listener for the scan event.
            barcodePicker.SetOnScanListener(this);

            // Show the scan user interface
            SetContentView(barcodePicker);
        }