Ejemplo n.º 1
0
        private EncodingOptions GetEncodeOptions()
        {
            if (this.cmbEncoderType.SelectedItem == null)
            {
                return(new EncodingOptions());
            }
            BarcodeFormat format = (BarcodeFormat)this.cmbEncoderType.SelectedValue;

            EncodingOptions options;

            switch (format)
            {
            case BarcodeFormat.QR_CODE:
                options = new ZXing.QrCode.QrCodeEncodingOptions()
                {
                    CharacterSet = "UTF-8"
                };

                break;

            case BarcodeFormat.PDF_417:
                options = new ZXing.PDF417.PDF417EncodingOptions()
                {
                    CharacterSet = "UTF-8"
                };
                break;

            case BarcodeFormat.DATA_MATRIX:
                options = new ZXing.Datamatrix.DatamatrixEncodingOptions
                {
                    SymbolShape = ZXing.Datamatrix.Encoder.SymbolShapeHint.FORCE_SQUARE
                };
                break;

            case BarcodeFormat.AZTEC:
                options = new ZXing.Aztec.AztecEncodingOptions();
                break;

            case BarcodeFormat.CODE_128:
                options = new ZXing.OneD.Code128EncodingOptions();
                break;

            default:
                options = new EncodingOptions();
                break;
            }
            if (this.CurrentBarcode != null)
            {
                options.Width  = this.CurrentBarcode.Rect.Width;
                options.Height = this.CurrentBarcode.Rect.Height;
            }
            return(options);
        }
        private void btnEncodeOptions_Click(object sender, EventArgs e)
        {
            if (cmbEncoderType.SelectedItem == null)
            {
                MessageBox.Show(this, "Please select a barcode format first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try
            {
                EncodingOptions options;
                switch ((BarcodeFormat)cmbEncoderType.SelectedItem)
                {
                case BarcodeFormat.QR_CODE:
                    options = new ZXing.QrCode.QrCodeEncodingOptions
                    {
                        Height = picEncodedBarCode.Height,
                        Width  = picEncodedBarCode.Width
                    };
                    break;

                case BarcodeFormat.MICRO_QR_CODE:
                    options = new ZXing.QrCode.QrCodeEncodingOptions
                    {
                        Height = 17,
                        Width  = 17,
                    };
                    break;

                case BarcodeFormat.PDF_417:
                    options = new ZXing.PDF417.PDF417EncodingOptions
                    {
                        Height = picEncodedBarCode.Height,
                        Width  = picEncodedBarCode.Width
                    };
                    break;

                case BarcodeFormat.DATA_MATRIX:
                    options = new ZXing.Datamatrix.DatamatrixEncodingOptions
                    {
                        Height      = picEncodedBarCode.Height,
                        Width       = picEncodedBarCode.Width,
                        SymbolShape = ZXing.Datamatrix.Encoder.SymbolShapeHint.FORCE_SQUARE
                    };
                    break;

                case BarcodeFormat.AZTEC:
                    options = new ZXing.Aztec.AztecEncodingOptions
                    {
                        Height = picEncodedBarCode.Height,
                        Width  = picEncodedBarCode.Width,
                    };
                    break;

                case BarcodeFormat.CODE_128:
                    options = new ZXing.OneD.Code128EncodingOptions
                    {
                        Height = picEncodedBarCode.Height,
                        Width  = picEncodedBarCode.Width,
                    };
                    break;

                default:
                    options = new EncodingOptions
                    {
                        Height = picEncodedBarCode.Height,
                        Width  = picEncodedBarCode.Width
                    };
                    break;
                }
                var dlg = new EncodingOptionsForm
                {
                    Options  = options,
                    Renderer = Renderer
                };
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    EncodingOptions = dlg.Options;
                    Renderer        = dlg.Renderer;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(this, exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
0
 private void btnEncodeOptions_Click(object sender, EventArgs e)
 {
    if (cmbEncoderType.SelectedItem == null)
    {
       MessageBox.Show(this, "Please select a barcode format first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
       return;
    }
    try
    {
       EncodingOptions options;
       switch ((BarcodeFormat)cmbEncoderType.SelectedItem)
       {
          case BarcodeFormat.QR_CODE:
             options = new ZXing.QrCode.QrCodeEncodingOptions
                        {
                           Height = picEncodedBarCode.Height,
                           Width = picEncodedBarCode.Width
                        };
             break;
          case BarcodeFormat.PDF_417:
             options = new ZXing.PDF417.PDF417EncodingOptions
                        {
                           Height = picEncodedBarCode.Height,
                           Width = picEncodedBarCode.Width
                        };
             break;
          case BarcodeFormat.DATA_MATRIX:
             options = new ZXing.Datamatrix.DatamatrixEncodingOptions
             {
                Height = picEncodedBarCode.Height,
                Width = picEncodedBarCode.Width,
                SymbolShape = ZXing.Datamatrix.Encoder.SymbolShapeHint.FORCE_SQUARE
             };
             break;
          case BarcodeFormat.AZTEC:
             options = new ZXing.Aztec.AztecEncodingOptions
             {
                Height = picEncodedBarCode.Height,
                Width = picEncodedBarCode.Width,
             };
             break;
          case BarcodeFormat.CODE_128:
             options = new ZXing.OneD.Code128EncodingOptions
             {
                Height = picEncodedBarCode.Height,
                Width = picEncodedBarCode.Width,
             };
             break;
          default:
             options = new EncodingOptions
                        {
                           Height = picEncodedBarCode.Height,
                           Width = picEncodedBarCode.Width
                        };
             break;
       }
       var dlg = new EncodingOptionsForm
                    {
                       Options = options,
                       Renderer = Renderer
                    };
       if (dlg.ShowDialog(this) == DialogResult.OK)
       {
          EncodingOptions = dlg.Options;
          Renderer = dlg.Renderer;
       }
    }
    catch (Exception exc)
    {
       MessageBox.Show(this, exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
 }