Exemplo n.º 1
0
        public IActionResult Get()
        {
            var req = this.Request;

            switch (req.Host.Host)
            {
            case "localhost":
            case "127.0.0.1":
                return(Content("地址为127.0.0.1或localhost时,二维码不可用。"));
            }
            var obj = new
            {
                Name     = name,
                Url      = $"{req.Scheme}://{req.Host}",
                Password = password
            };

            ZXing.Writer            formatWriter            = new ZXing.MultiFormatWriter();
            ZXing.IBarcodeWriterSvg barcodeWriter           = new ZXing.BarcodeWriterSvg();
            ZXing.BarcodeFormat     barcodeFormat           = ZXing.BarcodeFormat.QR_CODE;
            Dictionary <ZXing.EncodeHintType, object> hints = new Dictionary <ZXing.EncodeHintType, object>()
            {
                [ZXing.EncodeHintType.CHARACTER_SET] = "UTF-8"
            };

            ZXing.Common.BitMatrix bitMatrix = formatWriter.encode(JsonConvert.SerializeObject(obj), barcodeFormat, 400, 400, hints);
            var svgImage   = barcodeWriter.Write(bitMatrix);
            var svgContent = svgImage.Content;

            return(this.Content(svgContent, "image/svg+xml", Encoding.UTF8));
        }
Exemplo n.º 2
0
        public async Task Navigate()
        {
            ZXing.Mobile.MobileBarcodeScanner option = new ZXing.Mobile.MobileBarcodeScanner();

            var scanner = new ZXing.Mobile.MobileBarcodeScanningOptions()
            {
                TryHarder   = true,
                AutoRotate  = false,
                TryInverted = true,
                DelayBetweenContinuousScans = 2000,
            };

            ZXingScannerPage scanPage = new ZXingScannerPage(scanner);

            await Navigation.PushAsync(scanPage);

            scanPage.OnScanResult += (result) =>
            {
                scanPage.IsScanning = false;
                ZXing.BarcodeFormat barcodeFormat = result.BarcodeFormat;
                string type = barcodeFormat.ToString();
                Device.BeginInvokeOnMainThread(() =>
                {
                    Navigation.PopAsync();
                    DisplayAlert("The Barcode type is : " + type, "The text is : " + result.Text, "OK");
                });
            };
        }
Exemplo n.º 3
0
        private async Task NewMethod()
        {
            ScanImage.SetValue(IsVisibleProperty, true);

            try
            {
                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("No Camera", ":( No camera available.", "OK");

                    return;
                }
                else
                {
                    var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                    {
                        Directory   = "Sample",
                        Name        = "test.jpg",
                        SaveToAlbum = true,
                    });

                    if (file == null)
                    {
                        return;
                    }

                    if (ScanImage != null)
                    {
                        ScanImage.Source = ImageSource.FromStream(() =>
                        {
                            var stream = file.GetStream();
                            file.Dispose();
                            return(stream);
                        });
                        //  mainSTack.IsVisible = false;
                    }
                }

                var scan = new ZXingScannerPage();
                await Navigation.PushAsync(scan);

                scan.OnScanResult += (result) =>
                {
                    ZXing.BarcodeFormat barcodeFormat = result.BarcodeFormat;
                    string type = barcodeFormat.ToString();
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        await Navigation.PopAsync();

                        VinEnteredNumber.Text = result.Text;
                    });
                };
            }catch (Exception ex)
            {
                await DisplayAlert("Alert", " " + ex, "OK");
            }
        }
Exemplo n.º 4
0
 void HandleOnQRCodeFound(ZXing.BarcodeFormat barCodeType, string barCodeValue)
 {
     Debug.Log(barCodeType + " __ " + barCodeValue);
     lastBarcodeValue = barCodeValue;
     if (!runningQRscanned && !checkImage.IsActive())
     {
         QRscanned        = true;
         runningQRscanned = true;
     }
 }
Exemplo n.º 5
0
 private BarCodeType ZxingToBarcode(ZXing.BarcodeFormat format)
 {
     foreach (BarCodeType type in Enum.GetValues(typeof(BarCodeType)))
     {
         if (format.ToString().Equals(type.ToString()))
         {
             return(type);
         }
     }
     return(BarCodeType.DEFAULT);
 }
Exemplo n.º 6
0
        public void OptionGraphicsCodeType(object sender, EventArgs e)
        {
            ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem;

            if ((toolStripMenuItem != null) &&
                (toolStripMenuItem.Tag is ZXing.BarcodeFormat))
            {
                this.barcodeFormat = (ZXing.BarcodeFormat)toolStripMenuItem.Tag;
                this.txtQRCodeText_TextChanged(this.txtQRCodeText, null);
            }
        }
Exemplo n.º 7
0
        public HomePage() : base()
        {
            buttonScanDefaultOverlay = new Button {
                Text         = "Scan Barcode",
                AutomationId = "scanWithDefaultOverlay",
            };

            //setup options
            var options = new MobileBarcodeScanningOptions
            {
                AutoRotate = false,
                UseFrontCameraIfAvailable = false,
                TryHarder = true,
                //PossibleFormats = new List<ZXing.BarcodeFormat>
                //{
                //    ZXing.BarcodeFormat.EAN_8,
                //    ZXing.BarcodeFormat.EAN_13
                //}
            };

            buttonScanDefaultOverlay.Clicked += async delegate {
                scanPage = new ZXingScannerPage(options)
                {
                    DefaultOverlayTopText         = "Align the barcode within the frame",
                    DefaultOverlayBottomText      = "Scan the Barcode",
                    DefaultOverlayShowFlashButton = true
                };
                scanPage.OnScanResult += (result) => {
                    scanPage.IsScanning = false;

                    ZXing.BarcodeFormat barcodeFormat = result.BarcodeFormat;
                    string type = barcodeFormat.ToString();
                    Device.BeginInvokeOnMainThread(() => {
                        Navigation.PopAsync();
                        DisplayAlert("The Barcode type is : " + type, "The text is : " + result.Text, "OK");
                    });
                };

                await Navigation.PushAsync(scanPage);
            };


            var stack = new StackLayout();

            stack.Children.Add(buttonScanDefaultOverlay);

            Content = stack;
        }
        public BarcodeModel(
            string barcodeContent,
            System.Drawing.Imaging.ImageFormat imageFormat,
            ZXing.BarcodeFormat barcodeFormat = DEFAULT_BARCODE_FORMAT,
            int widthPx  = defaultWidthPx,
            int heightPx = defaultHeightPx)
        {
            ImageFormat    = imageFormat;
            BarcodeContent = barcodeContent;
            BarcodeFormat  = barcodeFormat;
            WidthPx        = widthPx;
            HeightPx       = heightPx;

            EncodeBarcodeSvg();
            EncodeBarcodeBmp();
        }
Exemplo n.º 9
0
        async void AddMaterialBtn_clicked(object sender, System.EventArgs e)
        {
            var scannerPage = new ZXingScannerPage();
            await Navigation.PushModalAsync(scannerPage);

            scannerPage.OnScanResult += (result) =>
            {
                scannerPage.IsScanning = false;
                ZXing.BarcodeFormat barcodeFormat = result.BarcodeFormat;
                string type = barcodeFormat.ToString();
                Device.BeginInvokeOnMainThread(() =>
                {
                    Navigation.PopModalAsync();
                    AddMaterialLine(result.ToString());
                });
            };
        }
Exemplo n.º 10
0
        void SetBarcode(ZXing.BarcodeFormat format, string value)
        {
            var w = new ZXing.BarcodeWriter();

            w.Options = new ZXing.Common.EncodingOptions {
                Width  = imageViewBarcode.Width,
                Height = imageViewBarcode.Height,
            };
            w.Format = format;

            try {
                using (var bitmap = w.Write(value)) {
                    imageViewBarcode.SetImageBitmap(bitmap);
                }
            } catch {
                imageViewBarcode.SetImageDrawable(null);
            }
        }
Exemplo n.º 11
0
    // QR found by cam handler
    private void HandleOnQRCodeFound(ZXing.BarcodeFormat barCodeType, string barCodeValue)
    {
        QRCodeManager.Instance.StopScanning();
        Product prod = Product.Parse(barCodeValue);

        if (prod == null)
        {
            QRCode qr = QRCode.QRParse(barCodeValue);
            if (ValidQR(qr.RawData))
            {
                UserUtilities.AllocatePoints(qr.TokenValue);
                IndicateScore(qr.TokenValue, true);
                SoundManager.Instance.PlaySound("CoinCollect");

                GameManager.Instance.analytics.LogEvent(new EventHitBuilder().SetEventCategory("Token Distribution").SetEventAction(qr.QRType.ToString()).SetEventValue(qr.TokenValue));

                if (qr.QRType != QRCode.QRTypes.Tokens)
                {
                    GameManager.Organizations Org = (GameManager.Organizations)Enum.Parse(typeof(GameManager.Organizations), qr.QRType.ToString());
                    if (GameManager.Instance.MiniGameEnabledOrgs.Contains(Org))
                    {
                        GameManager.Instance.Unlock(Org);
                    }
                }
            }
            else
            {
                DisplayNotification(true, "You have already redeemed this reward today.");
            }
        }
        else
        {
            GameObject        Popup = Instantiate(Confirmtion_Prefab, gameObject.transform);
            ConfirmationPopup conf  = Popup.GetComponent <ConfirmationPopup>();
            conf.prod         = prod;
            conf.Message.text = "Are you certain you would like to spend " + prod.TokenValue + " Tokens to recieve " + prod.ProductName + ".";
        }

        List_BTN.interactable = false;
        List_Tab.SetActive(true);
        Scan_BTN.interactable = true;
        Scan_Tab.SetActive(false);
    }
        protected async void SetUpScanner(Label labelToSet, ZXing.BarcodeFormat expectedFormat, string topText)
        {
            var scanner = new ZXing.Mobile.MobileBarcodeScanner
            {
                TopText          = topText,//"Scan Asset Id Code",
                CancelButtonText = "Exit"
            };

            var opts = new ZXing.Mobile.MobileBarcodeScanningOptions
            {
                PossibleFormats = new List <ZXing.BarcodeFormat> {
                    expectedFormat
                }
            };

            try
            {
                scanner.AutoFocus();
                var result = await scanner.Scan(opts);

                scanner.CameraUnsupportedMessage = "camera Unsupported";
                if (result != null)
                {
                    labelToSet.Text      = result.ToString();
                    labelToSet.TextColor = Color.Gray;
                    scanner.Cancel();
                }
                else
                {
                    scanner.Cancel();
                }
            }catch (Exception e) {
                await DisplayAlert(Constants.ERROR_TITLE, e.Message, Constants.BUTTON_POS);

                scanner.Cancel();
            }finally
            {
                scanner.Cancel();
            }
        }
Exemplo n.º 13
0
        private void btnScan_Clicked(object sender, EventArgs e)
        {
            ZXingScannerPage scanPage = new ZXingScannerPage();

            scanPage.IsScanning    = true;
            scanPage.OnScanResult += (result) =>
            {
                scanPage.IsScanning = false;
                ZXing.BarcodeFormat barcodeFormat = result.BarcodeFormat;
                string type = barcodeFormat.ToString();
                Device.BeginInvokeOnMainThread(() =>
                {
                    Navigation.PopModalAsync();

                    this.IsVisible = true;

                    edtCode.Text = result.Text.Trim();
                });
            };
            this.IsVisible = false;

            Navigation.PushModalAsync(scanPage);
        }
Exemplo n.º 14
0
        private void ScanImageTapped(object sender, System.EventArgs e)
        {
            var SelectedItem = ((ImageButton)sender).BindingContext as mstr_mealdelivered;

            _viewModel.SelectedOrderDetail = SelectedItem;
            ZXingScannerPage scan = new ZXingScannerPage();

            // await Navigation.PushAsync(scan);
            Navigation.PushAsync(scan);
            scan.OnScanResult += (result) =>
            {
                scan.IsScanning = false;
                ZXing.BarcodeFormat barcodeFormat = result.BarcodeFormat;
                string type = barcodeFormat.ToString();
                Device.BeginInvokeOnMainThread(async() =>
                {
                    //Navigation.PopAsync();
                    await Navigation.PopAsync();
                    string scanned_orderid = result.Text;
                    Image cmd = sender as Image;
                    _viewModel.ScanDeliveredOD(scanned_orderid, SelectedItem.OrderedID.ToString());
                });
            };
        }
Exemplo n.º 15
0
 void HandleOnQRCodeFound(ZXing.BarcodeFormat barCodeType, string barCodeValue)
 {
     Debug.Log(barCodeType + " __ " + barCodeValue);
     debugText.text = barCodeValue;
 }
Exemplo n.º 16
0
        public static BarcodeFormat ToInterop(this ZXing.BarcodeFormat format)
        {
            switch (format)
            {
            case ZXing.BarcodeFormat.AZTEC:
                return(BarcodeFormat.AZTEC);

            case ZXing.BarcodeFormat.All_1D:
                return(BarcodeFormat.All_1D);

            case ZXing.BarcodeFormat.CODABAR:
                return(BarcodeFormat.CODABAR);

            case ZXing.BarcodeFormat.CODE_128:
                return(BarcodeFormat.CODE_128);

            case ZXing.BarcodeFormat.CODE_39:
                return(BarcodeFormat.CODE_39);

            case ZXing.BarcodeFormat.CODE_93:
                return(BarcodeFormat.CODE_93);

            case ZXing.BarcodeFormat.DATA_MATRIX:
                return(BarcodeFormat.DATA_MATRIX);

            case ZXing.BarcodeFormat.EAN_13:
                return(BarcodeFormat.EAN_13);

            case ZXing.BarcodeFormat.EAN_8:
                return(BarcodeFormat.EAN_8);

            case ZXing.BarcodeFormat.IMB:
                return(BarcodeFormat.IMB);

            case ZXing.BarcodeFormat.ITF:
                return(BarcodeFormat.ITF);

            case ZXing.BarcodeFormat.MAXICODE:
                return(BarcodeFormat.MAXICODE);

            case ZXing.BarcodeFormat.MSI:
                return(BarcodeFormat.MSI);

            case ZXing.BarcodeFormat.PDF_417:
                return(BarcodeFormat.PDF_417);

            case ZXing.BarcodeFormat.PLESSEY:
                return(BarcodeFormat.PLESSEY);

            case ZXing.BarcodeFormat.QR_CODE:
                return(BarcodeFormat.QR_CODE);

            case ZXing.BarcodeFormat.RSS_14:
                return(BarcodeFormat.RSS_14);

            case ZXing.BarcodeFormat.RSS_EXPANDED:
                return(BarcodeFormat.RSS_EXPANDED);

            case ZXing.BarcodeFormat.UPC_A:
                return(BarcodeFormat.UPC_A);

            case ZXing.BarcodeFormat.UPC_E:
                return(BarcodeFormat.UPC_E);

            case ZXing.BarcodeFormat.UPC_EAN_EXTENSION:
                return(BarcodeFormat.UPC_EAN_EXTENSION);

            default:
                return(BarcodeFormat.QR_CODE);
            }
        }
Exemplo n.º 17
0
        private void InitializeBeaconViewRendering()
        {
            BarcodeControllerName = Rendering.Parameters[MobileFieldNames.BarcodeControllerViewRenderingParameters.BarcodeControllerName];

            BarcodeControllerAction = Rendering.Parameters[MobileFieldNames.BarcodeControllerViewRenderingParameters.BarcodeControllerAction];

            var linkFieldNameParameter = Rendering.Parameters[MobileFieldNames.BarcodeViewRenderingParameters.LinkFieldName] ?? null;
            var generalLinkParameter   = Rendering.Parameters[MobileFieldNames.BarcodeViewRenderingParameters.GeneralLink] ?? null;

            BarcodeFormatParameter = Rendering.Parameters[MobileFieldNames.BarcodeViewRenderingParameters.BarcodeFormat] ?? defaultBarcodeFormat;
            ImageFormatParameter   = Rendering.Parameters[MobileFieldNames.BarcodeViewRenderingParameters.ImageFormat] ?? defaultImageFormat;

            int w = defaultWidthPx;
            int h = defaultHeightPx;

            int.TryParse(Rendering.Parameters[MobileFieldNames.BarcodeViewRenderingParameters.WidthPx], out w);
            int.TryParse(Rendering.Parameters[MobileFieldNames.BarcodeViewRenderingParameters.HeightPx], out h);

            ZXing.BarcodeFormat barcodeFormat = ZXing.BarcodeFormat.QR_CODE;
            ImageFormat         imageFormat   = ImageFormat.Png;

            barcodeFormat = (ZXing.BarcodeFormat)Enum.Parse(typeof(ZXing.BarcodeFormat), BarcodeFormatParameter.Trim());

            switch (ImageFormatParameter.ToLower())
            {
            case "svg":
                break;

            case "bmp":
                imageFormat = ImageFormat.Bmp;
                break;

            case "emf":
                imageFormat = ImageFormat.Emf;
                break;

            case "gif":
                imageFormat = ImageFormat.Gif;
                break;

            case "icon":
                imageFormat = ImageFormat.Icon;
                break;

            case "jpeg":
            case "jpg":
                imageFormat = ImageFormat.Jpeg;
                break;

            case "png":
                imageFormat = ImageFormat.Png;
                break;

            case "tiff":
                imageFormat = ImageFormat.Tiff;
                break;

            case "wmf":
                imageFormat = ImageFormat.Wmf;
                break;

            default:
                throw new ArgumentException("Image format isn't supported", ImageFormatParameter.ToLower());
            }


            var buttonLink = (string)null;

            if (!string.IsNullOrEmpty(BarcodeControllerName) &&
                !string.IsNullOrEmpty(BarcodeControllerAction))
            {
                var r = new Sitecore.Mvc.Controllers.ControllerRunner(
                    BarcodeControllerName,
                    BarcodeControllerAction);
                buttonLink = r.Execute();

                // formFieldControllerValue = Html.Partial(Model.FormFieldValueControllerAction, Model.FormFieldValueControllerName);
            }

            if (string.IsNullOrEmpty(buttonLink))
            {
                buttonLink = string.Empty;
            }


            if (string.IsNullOrEmpty(buttonLink))
            {
                EmbeddedBarcodeImage = new HtmlString("Badge Error");
                SvgBarcodeImage      = new HtmlString("Badge Error");
                return;
            }

            BarcodeModel = new BarcodeModel(buttonLink, imageFormat, barcodeFormat, w, h);

            System.Web.Mvc.TagBuilder tagBuilder = new System.Web.Mvc.TagBuilder("img");
            // tagBuilder.MergeAttributes<string, object>(tagParameters);

            string base64ImageString = string.Concat("data:", GetMimeType(imageFormat), ";base64,", Convert.ToBase64String(BarcodeModel.BarcodeImageEncoded));

            tagBuilder.Attributes.Add(new KeyValuePair <string, string>("src", base64ImageString));

            EmbeddedBarcodeImage = new HtmlString(tagBuilder.ToString(System.Web.Mvc.TagRenderMode.SelfClosing));

            SvgBarcodeImage = new HtmlString(BarcodeModel.BarcodeImageSvg);
        }
Exemplo n.º 18
0
        public async static Task <ZXingScannerPage> CapturarCodigoAsync(ZXingScannerPage scanpage, string titulo, ZXing.BarcodeFormat formato)
        {
            if (scanpage == null)
            {
                var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
                options.PossibleFormats = new List <ZXing.BarcodeFormat>()
                {
                    formato
                };

#if __ANDROID__
                //Initialize scanner first
                //    MobileBarcodeScanner.Initialize (Application);
#endif
                scanpage            = new ZXingScannerPage(options);
                scanpage.IsScanning = true;
            }

            scanpage.Title = titulo;
            return(scanpage);
        }
 public void OnGenerateUPC_A()
 {
     codeFormat = ZXing.BarcodeFormat.UPC_A;
 }
 public void OnGenerateITF()
 {
     codeFormat = ZXing.BarcodeFormat.ITF;
 }
 public void OnGenerateCODE_128()
 {
     codeFormat = ZXing.BarcodeFormat.CODE_128;
 }
 public void OnGenerateCODE_39()
 {
     codeFormat = ZXing.BarcodeFormat.CODE_39;
 }
 public void OnGenerateEAN_13()
 {
     codeFormat = ZXing.BarcodeFormat.EAN_13;
 }
 public void OnGenerateQRCode()
 {
     codeFormat = ZXing.BarcodeFormat.QR_CODE;
 }
Exemplo n.º 25
0
        public async static Task <ZXingScannerPage> CapturarQRCodeAsync(ZXingScannerPage scanPage, string titulo, ZXing.BarcodeFormat barcodeFormat)
        {
            if (scanPage == null)
            {
                var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
                options.PossibleFormats = new List <ZXing.BarcodeFormat>()
                {
                    barcodeFormat
                };

#if __ANDROID__
                //para codigo espeficifico do Android
                //Initialize the scanner first so it can track the current context
                MobileBarcodeScanner.Initialize(Application);
#endif

                scanPage            = new ZXingScannerPage(options);
                scanPage.IsScanning = true;
            }

            scanPage.Title = titulo;
            return(scanPage);
        }
Exemplo n.º 26
0
        public static ZXingScannerPage CapturarQRCode(ZXingScannerPage scannerPage, string titulo, ZXing.BarcodeFormat formato)
        {
            if (scannerPage == null)
            {
                var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
                options.PossibleFormats = new List <ZXing.BarcodeFormat>()
                {
                    formato
                };


                // diretiva de compilação especifica para o Android
#if __Android__
                // Initialize the scanner frist so it can track the current context
                MobileBarcodeScanner.Initialize(Application);
#endif
                scannerPage            = new ZXingScannerPage(options);
                scannerPage.IsScanning = true;
            }

            scannerPage.Title = titulo;

            return(scannerPage);
        }
Exemplo n.º 27
0
 public UIImage Render(BitMatrix matrix, ZXing.BarcodeFormat format, string content)
 {
     return(RenderMatrix(matrix));
 }
Exemplo n.º 28
0
        public async static Task <ZXingScannerPage> CaptureQRCodeAsync(ZXingScannerPage scanPage, string title, ZXing.BarcodeFormat format)
        {
            //Create page do QRCode
            if (scanPage == null)
            {
                var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
                options.PossibleFormats = new List <ZXing.BarcodeFormat>
                {
                    format
                };
//Start correctly the plugins of Scanner
#if __ANDROID__
                MobileBarcodeScanner.Initialize(Application);
#endif

                scanPage            = new ZXingScannerPage(options); //Creata a new instance
                scanPage.IsScanning = true;                          //Start camera and qrCode
            }
            scanPage.Title = title;                                  //Title
            return(scanPage);                                        //return page
        }
Exemplo n.º 29
0
 public UIImage Render(BitMatrix matrix, ZXing.BarcodeFormat format, string content, EncodingOptions options)
 {
     return(RenderMatrix(matrix));
 }
Exemplo n.º 30
0
        public EncoderViewController(string title, ZXing.BarcodeFormat format) : base(UITableViewStyle.Grouped, new RootElement(title), true)
        {
            this.Root.UnevenRows = true;

            this.Format = format;
        }