Пример #1
0
 private void BarcodeDetected(object sender, BarcodeDetectedEventArgs e)
 {
     barCodeBorder.Child = e.GetBarcodeBorderUIVideoUniformFill(barCodeBorder.ActualWidth, barCodeBorder.ActualHeight);
     DisplayResult(e.Result);
     if (_resetTextAction != null)
     {
         _resetTextAction.Start();
     }
 }
Пример #2
0
        private async void BarcodeTimer_Tick(object sender, EventArgs e)
        {
            ThrowIfDisposed();
            if (!_inited)
            {
                return;
            }

            if (!_previewSize.HasValue)
            {
                return;
            }
            int width  = (int)_previewSize.Value.Width;
            int height = (int)_previewSize.Value.Height;

            // for barcode
            if (AutoDetectBarcode)
            {
                if (_barcodeDecoding == true)
                {
                    return;
                }
                _barcodeDecoding = true;
                try
                {
                    var result = await DetectBarcodeAsync(width, height);

                    if (result != null)
                    {
                        // raise BarcodeDetected
                        BarcodeDetectedEventArgs args = new BarcodeDetectedEventArgs(result);
                        args.HostImageSize = new Size(width, height);
                        if (args.IsQRCode && result.ResultMetadata.ContainsKey(ResultMetadataType.QRCODE_DIMENSION))
                        {
                            int dimension = (int)result.ResultMetadata[ResultMetadataType.QRCODE_DIMENSION];
                            Debug.Assert(result.ResultPoints.Length >= 3);
                            if (result.ResultPoints.Length >= 3)
                            {
                                var p1 = new Point(result.ResultPoints[0].X, result.ResultPoints[0].Y);
                                var p2 = new Point(result.ResultPoints[1].X, result.ResultPoints[1].Y);
                                var p3 = new Point(result.ResultPoints[2].X, result.ResultPoints[2].Y);
                                args.BarcodePosition = new BarcodePosition(p1, p2, p3, dimension, width, height);
                            }
                        }

                        if (BarcodeDetected != null)
                        {
                            BarcodeDetected(this, args);
                        }
                    }
                }
                catch (ObjectDisposedException)
                {
                    throw new CardCaptureDeviceDisposedException();
                }
                catch
                {
                }
                finally
                {
                    _barcodeDecoding = false;
                }
            }

            ThrowIfDisposed();
        }