Пример #1
0
        private async void CameraView_OnDetected(object sender, GoogleVisionBarCodeScanner.OnDetectedEventArg e)
        {
            List <GoogleVisionBarCodeScanner.BarcodeResult> obj = e.BarcodeResults;

            string result = string.Empty;

            for (int i = 0; i < obj.Count; i++)
            {
                result += $"Type : {obj[i].BarcodeType}, Value : {obj[i].DisplayValue}{Environment.NewLine}";
            }
            Device.BeginInvokeOnMainThread(async() =>
            {
                await DisplayAlert("Result", result, "OK");
                await Navigation.PopModalAsync();
            });
        }
Пример #2
0
        private async void CameraView_OnDetected(object sender, GoogleVisionBarCodeScanner.OnDetectedEventArg e)
        {
            Device.BeginInvokeOnMainThread(() => GoogleVisionBarCodeScanner.Methods.SetIsScanning(true));

            List <GoogleVisionBarCodeScanner.BarcodeResult> barcodes = e.BarcodeResults;

            foreach (var barcode in barcodes)
            {
                RealtimeBarcodeInfo info;
                Point target = new Point(barcode.Points[0].x * grid.Width, barcode.Points[0].y * grid.Height);

                if (!BarcodeInfo.ContainsKey(barcode.DisplayValue))
                {
                    //found new barcode

                    info = new RealtimeBarcodeInfo()
                    {
                        Text            = $"{barcode.DisplayValue}\n{barcode.BarcodeType}",
                        CurrentPosition = target
                    };
                    BarcodeInfo[barcode.DisplayValue] = info;

                    await Device.InvokeOnMainThreadAsync(() =>
                    {
                        /*
                         * Create GUI for new barcode
                         *
                         * Frame - transparent, fully covers camera view
                         *  -Grid  - margin is set on this to adjust position
                         *   -Label - Content
                         */

                        var frame = new Frame()
                        {
                            Padding         = 0,
                            BackgroundColor = Color.Transparent
                        };

                        var barcodeGrid = new Grid()
                        {
                            BackgroundColor   = Color.Cyan,
                            Opacity           = .85d,
                            Margin            = new Thickness(0, 0, 0, 0),
                            WidthRequest      = 200,
                            HeightRequest     = 75,
                            HorizontalOptions = LayoutOptions.Start,
                            VerticalOptions   = LayoutOptions.Start
                        };
                        barcodeGrid.RowDefinitions.Add(new RowDefinition()
                        {
                            Height = GridLength.Star
                        });

                        frame.Content = barcodeGrid;

                        var textLabel = new Label()
                        {
                            Text = info.Text
                        };

                        barcodeGrid.Children.Add(textLabel);
                        Grid.SetRow(textLabel, 0);

                        info.OuterFrame = frame;
                        info.Grid       = barcodeGrid;
                        info.TextLabel  = textLabel;

                        grid.Children.Add(frame);
                        Grid.SetRow(frame, 1);
                    });
                }
                else
                {
                    info = BarcodeInfo[barcode.DisplayValue];
                }

                info.LastScanned    = DateTime.Now;
                info.TargetPosition = target;
            }
        }