コード例 #1
1
        public async Task<BarCodeResult> ReadAsync(BarCodeScannerOptions options) {
#if __IOS__
            var scanner = new MobileBarcodeScanner { UseCustomOverlay = false };
#elif ANDROID
            var scanner = new MobileBarcodeScanner(Forms.Context) { UseCustomOverlay = false };
#elif WINDOWS_PHONE
            var scanner = new MobileBarcodeScanner(System.Windows.Deployment.Current.Dispatcher) { UseCustomOverlay = false };
#endif
            options = options ?? this.DefaultOptions;
            if (!String.IsNullOrWhiteSpace(options.TopText)) 
                scanner.TopText = options.TopText;
            
            if (!String.IsNullOrWhiteSpace(options.BottomText)) 
                scanner.BottomText = options.BottomText;
            
            if (!String.IsNullOrWhiteSpace(options.FlashlightText)) 
                scanner.FlashButtonText = options.FlashlightText;
            
            if (!String.IsNullOrWhiteSpace(options.CancelText)) 
                scanner.CancelButtonText = options.CancelText;

            var cfg = GetXingConfig(options);
            var result = await scanner.Scan(cfg);
            return (result == null || String.IsNullOrWhiteSpace(result.Text)
                ? BarCodeResult.Fail
                : new BarCodeResult(result.Text, FromXingFormat(result.BarcodeFormat))
            );
        }
コード例 #2
0
 public void Read(Action<BarCodeResult> onRead, Action<Exception> onError, BarCodeScannerOptions options) {
     this.ReadAsync(options)
         .ContinueWith(x => {
             if (x.Exception == null)
                 onRead(x.Result);
             else if (onError != null)
                 onError(x.Exception);
         });
 }
コード例 #3
0
 public void Read(Action <BarCodeResult> onRead, Action <Exception> onError, BarCodeScannerOptions options)
 {
     this.ReadAsync(options)
     .ContinueWith(x => {
         if (x.Exception == null)
         {
             onRead(x.Result);
         }
         else if (onError != null)
         {
             onError(x.Exception);
         }
     });
 }
コード例 #4
0
        public async Task <BarCodeResult> ReadAsync(BarCodeScannerOptions options)
        {
#if __IOS__
            var scanner = new MobileBarcodeScanner {
                UseCustomOverlay = false
            };
#elif ANDROID
            var scanner = new MobileBarcodeScanner(Forms.Context)
            {
                UseCustomOverlay = false
            };
#elif WINDOWS_PHONE
            var scanner = new MobileBarcodeScanner(System.Windows.Deployment.Current.Dispatcher)
            {
                UseCustomOverlay = false
            };
#endif
            options = options ?? this.DefaultOptions;
            if (!String.IsNullOrWhiteSpace(options.TopText))
            {
                scanner.TopText = options.TopText;
            }

            if (!String.IsNullOrWhiteSpace(options.BottomText))
            {
                scanner.BottomText = options.BottomText;
            }

            if (!String.IsNullOrWhiteSpace(options.FlashlightText))
            {
                scanner.FlashButtonText = options.FlashlightText;
            }

            if (!String.IsNullOrWhiteSpace(options.CancelText))
            {
                scanner.CancelButtonText = options.CancelText;
            }

            var cfg    = GetXingConfig(options);
            var result = await scanner.Scan(cfg);

            return(result == null || String.IsNullOrWhiteSpace(result.Text)
                ? BarCodeResult.Fail
                : new BarCodeResult(result.Text, FromXingFormat(result.BarcodeFormat))
                   );
        }
コード例 #5
0
        private static MobileBarcodeScanningOptions GetXingConfig(BarCodeScannerOptions opts) {
            var def = ZXing.Mobile.MobileBarcodeScanningOptions.Default;

            var config = new MobileBarcodeScanningOptions {
                AutoRotate = def.AutoRotate,
                CharacterSet = opts.CharacterSet ?? def.CharacterSet,
                DelayBetweenAnalyzingFrames = opts.DelayBetweenAnalyzingFrames ?? def.DelayBetweenAnalyzingFrames,
                InitialDelayBeforeAnalyzingFrames = (opts.InitialDelayBeforeAnalyzingFrames ?? def.InitialDelayBeforeAnalyzingFrames),
                PureBarcode = opts.PureBarcode,
                TryHarder = opts.TryHarder,
                TryInverted = opts.TryInverted,
                UseFrontCameraIfAvailable = opts.UseFrontCameraIfAvailable
            };
            if (opts.Formats != null && opts.Formats.Count > 0) {
                config.PossibleFormats = opts.Formats
                    .Select(x => (BarcodeFormat)(int)x)
                    .ToList();
            }
            return config;
        }
コード例 #6
0
        private static MobileBarcodeScanningOptions GetXingConfig(BarCodeScannerOptions opts)
        {
            var def = ZXing.Mobile.MobileBarcodeScanningOptions.Default;

            var config = new MobileBarcodeScanningOptions {
                AutoRotate   = def.AutoRotate,
                CharacterSet = opts.CharacterSet ?? def.CharacterSet,
                DelayBetweenAnalyzingFrames       = opts.DelayBetweenAnalyzingFrames ?? def.DelayBetweenAnalyzingFrames,
                InitialDelayBeforeAnalyzingFrames = (opts.InitialDelayBeforeAnalyzingFrames ?? def.InitialDelayBeforeAnalyzingFrames),
                PureBarcode = opts.PureBarcode,
                TryHarder   = opts.TryHarder,
                TryInverted = opts.TryInverted,
                UseFrontCameraIfAvailable = opts.UseFrontCameraIfAvailable
            };

            if (opts.Formats != null && opts.Formats.Count > 0)
            {
                config.PossibleFormats = opts.Formats
                                         .Select(x => (BarcodeFormat)(int)x)
                                         .ToList();
            }
            return(config);
        }
コード例 #7
0
 public BarCodeScanner() {
     this.DefaultOptions = new BarCodeScannerOptions();
 }
コード例 #8
0
 public BarCodeScanner()
 {
     this.DefaultOptions = new BarCodeScannerOptions();
 }