Beispiel #1
0
        public bool RefreshBarcode()
        {
            //Debug.WriteLine("ActualW: "+Width+"  ActualH: "+Height);
            try
            {
                int hSize = 0;
                if (Height > Width)
                {
                    hSize = (int)Height;
                }
                else
                {
                    hSize = (int)Width;
                }


                ZXing.Presentation.BarcodeWriter writer = new ZXing.Presentation.BarcodeWriter
                {
                    Format  = BarcodeFormat.QR_CODE,
                    Options = new ZXing.Common.EncodingOptions
                    {
                        Height = (int)Height,
                        Width  = (int)Width,
                        Margin = 0
                    }
                };

                if (type == BarcodeType.Barcode_Type.QRCode)
                {
                    writer.Format         = BarcodeFormat.QR_CODE;
                    writer.Options.Width  = hSize;
                    writer.Options.Height = hSize;
                }
                else if (type == BarcodeType.Barcode_Type.EAN13)
                {
                    writer.Format = BarcodeFormat.EAN_13;
                }
                else if (type == BarcodeType.Barcode_Type.EAN8)
                {
                    writer.Format = BarcodeFormat.EAN_8;
                }
                else if (type == BarcodeType.Barcode_Type.Code128)
                {
                    writer.Format = BarcodeFormat.CODE_128;
                }
                else if (type == BarcodeType.Barcode_Type.Codabar)
                {
                    writer.Format = BarcodeFormat.CODABAR;
                }

                BarcodeImage.Source = writer.Write(text);
                return(true);
            }catch (Exception ex)
            {
                Debug.WriteLine("Barcode Error: " + ex);
                return(false);
            }
        }
Beispiel #2
0
        private void btnEncode_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                imageBarcodeEncoder.Visibility         = Visibility.Hidden;
                imageBarcodeEncoderGeometry.Visibility = Visibility.Hidden;

                switch (cmbRendererType.SelectedItem.ToString())
                {
                case "WriteableBitmap":
                {
                    var writer = new BarcodeWriter
                    {
                        Format  = (BarcodeFormat)cmbEncoderType.SelectedItem,
                        Options = new ZXing.Common.EncodingOptions
                        {
                            Height = (int)imageBarcodeEncoder.Height,
                            Width  = (int)imageBarcodeEncoder.Width,
                            Margin = 0
                        }
                    };
                    var image = writer.Write(txtBarcodeContentEncode.Text);
                    imageBarcodeEncoder.Source     = image;
                    imageBarcodeEncoder.Visibility = Visibility.Visible;
                }
                break;

                case "XAML Geometry":
                {
                    var writer = new BarcodeWriterGeometry
                    {
                        Format  = (BarcodeFormat)cmbEncoderType.SelectedItem,
                        Options = new ZXing.Common.EncodingOptions
                        {
                            Height = (int)imageBarcodeEncoder.Height,
                            Width  = (int)imageBarcodeEncoder.Width,
                            Margin = 0
                        }
                    };
                    var image = writer.Write(txtBarcodeContentEncode.Text);
                    imageBarcodeEncoderGeometry.Data       = image;
                    imageBarcodeEncoderGeometry.Visibility = Visibility.Visible;
                }
                break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #3
0
        private void GenerateQrCode(string text)
        {
            QRCodeWriter qrWriter = new QRCodeWriter();
            Dictionary <ZXing.EncodeHintType, object> hints = new Dictionary <ZXing.EncodeHintType, object>();

            hints.Add(ZXing.EncodeHintType.CHARACTER_SET, "windows-1251");
            hints.Add(ZXing.EncodeHintType.MARGIN, 1);
            ZXing.Common.BitMatrix matrix = qrWriter.encode(text.Trim(), ZXing.BarcodeFormat.QR_CODE, 640, 640, hints);

            ZXing.Presentation.BarcodeWriter writer = new ZXing.Presentation.BarcodeWriter();
            WriteableBitmap wb = writer.Write(matrix);

            this.image.Source = wb;
        }
Beispiel #4
0
        private BitmapImage GenerateBarcodeImage(string barcodeContent, BarcodeFormat barcodeType)
        {
            var barcodeWriter = new ZXing.Presentation.BarcodeWriter();

            barcodeWriter.Format  = barcodeType;
            barcodeWriter.Options = new EncodingOptions
            {
                Width  = BARCODE_WIDTH,
                Height = BARCODE_HEIGHT
            };

            var bc = barcodeWriter.Write(barcodeContent);

            return(ToBitMapImage(bc));
        }
Beispiel #5
0
        /// <summary>
        /// PayUrl  to  QR code 400*400
        /// </summary>
        /// <param name="paylink"></param>
        void StrToQRCode(string paylink)
        {
            var writer = new BarcodeWriter
            {
                Format  = BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Height = 400,
                    Width  = 400,
                    Margin = 0
                }
            };
            var image = writer.Write(paylink);

            this.image.Source  = image;
            this.label.Content = "扫一扫 微信支付";
        }
        private void GenQR(string value)
        {
            EncodingOptions option = new EncodingOptions();

            option.Hints.Add(EncodeHintType.CHARACTER_SET, "utf-8");
            option.Hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
            option.Hints.Add(EncodeHintType.WIDTH, 200);
            option.Hints.Add(EncodeHintType.HEIGHT, 200);

            BarcodeWriter writer = new BarcodeWriter
            {
                Format  = BarcodeFormat.QR_CODE,
                Options = option
            };

            if (string.IsNullOrEmpty(value))
            {
                QRCodeView.imageHolder.Source = new BitmapImage();
                return;
            }

            var result = writer.Write(value);

            BitmapImage bmImage = new BitmapImage();

            using (MemoryStream stream = new MemoryStream())
            {
                PngBitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(result));
                encoder.Save(stream);
                bmImage.BeginInit();
                bmImage.CacheOption  = BitmapCacheOption.OnLoad;
                bmImage.StreamSource = stream;
                bmImage.EndInit();
                bmImage.Freeze();
            }

            QRCodeView.imageHolder.Source = bmImage;
        }
Beispiel #7
0
      private void btnEncode_Click(object sender, RoutedEventArgs e)
      {
         imageBarcodeEncoder.Visibility = Visibility.Hidden;
         imageBarcodeEncoderGeometry.Visibility = Visibility.Hidden;

         switch (cmbRendererType.SelectedItem.ToString())
         {
            case "WriteableBitmap":
               {
                  var writer = new BarcodeWriter
                     {
                        Format = (BarcodeFormat)cmbEncoderType.SelectedItem,
                        Options = new ZXing.Common.EncodingOptions
                           {
                              Height = (int)imageBarcodeEncoder.Height,
                              Width = (int)imageBarcodeEncoder.Width,
                              Margin = 0
                           }
                     };
                  var image = writer.Write(txtBarcodeContentEncode.Text);
                  imageBarcodeEncoder.Source = image;
                  imageBarcodeEncoder.Visibility = Visibility.Visible;
               }
               break;
            case "XAML Geometry":
               {
                  var writer = new BarcodeWriterGeometry
                     {
                        Format = (BarcodeFormat) cmbEncoderType.SelectedItem,
                        Options = new ZXing.Common.EncodingOptions
                           {
                              Height = (int) imageBarcodeEncoder.Height,
                              Width = (int) imageBarcodeEncoder.Width,
                              Margin = 0
                           }
                     };
                  var image = writer.Write(txtBarcodeContentEncode.Text);
                  imageBarcodeEncoderGeometry.Data = image;
                  imageBarcodeEncoderGeometry.Visibility = Visibility.Visible;
               }
               break;
         }
      }