zxing. NET multiple Barcode format generation

Source: Internet
Author: User

: http://zxingnet.codeplex.com/

Zxing.net is a tool for barcode and QR code under the. NET platform, which is very convenient to use.

This article mainly describes the generation of various types of bar codes.

Suitable for scenes, label visual design, custom barcode type, preview.

Traverse all barcode types supported by zxing
if (RB = = Rb1wm) {foreach (Barcodeformat format in Enum.getvalues (typeof (Barcodeformat))) {if (format! = barcodeformat.all_1d) cbxBarcodeFormat.Items.Add (forma                T.tostring ()); } cbxBarcodeFormat.Items.Remove (Barcodeformat.qr_code.                ToString ());                CbxBarcodeFormat.Items.Remove (BarcodeFormat.AZTEC.ToString ()); CbxBarcodeFormat.Items.Remove (Barcodeformat.data_matrix.                ToString ());            CbxBarcodeFormat.Items.Remove (BarcodeFormat.PDF_417.ToString ()); } if (RB = = RB2WM) {cbxBarcodeFormat.Items.Add (barcodeformat.qr_code.                ToString ());                CBXBARCODEFORMAT.ITEMS.ADD (BarcodeFormat.AZTEC.ToString ()); CBXBARCODEFORMAT.ITEMS.ADD (Barcodeformat.data_matrix.                ToString ());            CBXBARCODEFORMAT.ITEMS.ADD (BarcodeFormat.PDF_417.ToString ()); }
Generate barcodes based on the type of selection
Bitmap Bitmap = new Bitmap (pbxbarcode.width, pbxbarcode.height);            Graphics g = graphics.fromimage (bitmap);            G.clear (Color.White);            Format = (Barcodeformat) enum.parse (typeof (Barcodeformat), cbxBarcodeFormat.SelectedItem.ToString ()); try {var options = new ZXing.Common.EncodingOptions {Purebar                Code =!chxdisplaybarcode.checked};                        #region Write Image switch (Format) {case Barcodeformat.qr_code according to the barcode type: #region QRCode if (cbxErrorLevel.SelectedItem.ToString ().                        Equals ("L")) Errorcorrectionlevel = QR_ERRORCORRECTIONLEVEL.L; if (cbxErrorLevel.SelectedItem.ToString ().                        Equals ("H")) Errorcorrectionlevel = qr_errorcorrectionlevel.h; if (cbxErrorLevel.SelectedItem.ToString (). EquALS ("M")) Errorcorrectionlevel = QR_ERRORCORRECTIONLEVEL.M; if (cbxErrorLevel.SelectedItem.ToString ().                        Equals ("Q")) Errorcorrectionlevel = QR_ERRORCORRECTIONLEVEL.Q;                        Errorcorrectionlevel level = NULL;                                Switch (errorcorrectionlevel) {case qr_errorcorrectionlevel.h:                                level = Zxing.qrcode.internal.errorcorrectionlevel.h;                            Break                                Case qr_errorcorrectionlevel.m:level = ZXING.QRCODE.INTERNAL.ERRORCORRECTIONLEVEL.M;                            Break                                Case qr_errorcorrectionlevel.l:level = ZXING.QRCODE.INTERNAL.ERRORCORRECTIONLEVEL.L;                            Break                  Case QR_ERRORCORRECTIONLEVEL.Q:              level = ZXING.QRCODE.INTERNAL.ERRORCORRECTIONLEVEL.Q;                        Break                            } qrcodeencodingoptions qr_options = new Qrcodeencodingoptions { Margin = 0, Disableeci = true, CharacterSet = "UTF-8 ", errorcorrection = level, Purebarcode =!chxdisplaybarcode.checked                        , Width = pbxbarcode.width, Height = Pbxbarcode.height                        };                        var qrwriter = new Zxing.barcodewriter ();                        Qrwriter.format = Barcodeformat.qr_code;                        Qrwriter.options = qr_options;                        #endregion bitmap = Qrwriter.write (TbxBarcodeValue.Text.Trim ()); Barcodeoptionschanged?. Invoke (Qrwriter.options, FormaT, bitmap);                    Break  Case barcodeformat.pdf_417: #region PDF417 pdf417encodingoptions pdf_options = new Pdf417encodingoptions {Margin = 0, Di                            Sableeci = true, CharacterSet = "UTF-8", Width = Pbxbarcode.width,                        Height = pbxbarcode.height, Purebarcode =!chxdisplaybarcode.checked                        };                        var pdf417writer = new Zxing.barcodewriter ();                        Pdf417writer.format = barcodeformat.pdf_417;                        Pdf417writer.options = pdf_options;                        #endregion bitmap = Pdf417writer.write (TbxBarcodeValue.Text.Trim ()); Barcodeoptionschanged?.                       Invoke (Pdf417writer.options, Format, bitmap); Break  Case Barcodeformat.data_matrix: #region Datamatrix datamatrixencodingoptions                            Datamatrix_options = new Datamatrixencodingoptions {Margin = 0, Symbolshape = (ZXing.Datamatrix.Encoder.SymbolShapeHint) (Enum.parse (typeof (Zxing.datamatrix.encoder.s                            Ymbolshapehint), cbxDataMatrixOption.SelectedItem.ToString ()), Width = Pbxbarcode.width,                        Height = pbxbarcode.height, Purebarcode =!chxdisplaybarcode.checked,                        };                        var datamatrixwriter = new Zxing.barcodewriter ();                        Datamatrixwriter.format = Barcodeformat.data_matrix;                        Datamatrixwriter.options = datamatrix_options;   #endregion bitmap = Datamatrixwriter.write (TbxBarcodeValue.Text.Trim ());                     Barcodeoptionschanged?.                        Invoke (Datamatrixwriter.options, Format, bitmap);                    Break Case Barcodeformat.aztec: #region AZTEC ZXing.Aztec.AztecEncodingOptions AZT                            Ecencodingoptions = new ZXing.Aztec.AztecEncodingOptions {Margin = 0,                            Errorcorrection = 2, Purebarcode =!chxdisplaybarcode.checked,                        Layers = 16};                        var aztecwriter = new Zxing.barcodewriter ();                        Aztecwriter.format = Barcodeformat.aztec;                        Aztecwriter.options = aztecencodingoptions;                        #endregion bitmap = Aztecwriter.write (TbxBarcodeValue.Text.Trim ()); Barcodeoptionschanged?.                        Invoke (Aztecwriter.options, Format, bitmap); BreaK Case barcodeformat.code_128: #region Code128 ZXing.OneD.Code128EncodingOptio                             NS Code128_options = new ZXing.OneD.Code128EncodingOptions {Margin = 0,                             Purebarcode =!chxdisplaybarcode.checked, Width = Pbxbarcode.width,                        Height = pbxbarcode.height, Forcecodesetb = True                        };                        var code128_writer = new Zxing.barcodewriter ();                        Code128_writer.format = barcodeformat.code_128;                        Code128_writer.options = code128_options;                        #endregion bitmap = Code128_writer.write (TbxBarcodeValue.Text.Trim ()); Barcodeoptionschanged?.                        Invoke (Code128_writer.options, Format, bitmap);                    Break Case BarcodeforMat.                        Codabar:var codebar_writer = new Zxing.barcodewriter ();                        Codebar_writer.format = Barcodeformat.codabar;                        Codebar_writer.options = Options;                        Bitmap = Codebar_writer.write (TbxBarcodeValue.Text.Trim ()); Barcodeoptionschanged?.                        Invoke (Options, Format, bitmap);                    Break                        Case BarcodeFormat.EAN_13:var Ean13_writer = new Zxing.barcodewriter ();                        Ean13_writer.format = barcodeformat.ean_13;                        Ean13_writer.options = Options;                        Bitmap = Ean13_writer.write (TbxBarcodeValue.Text.Trim ()); Barcodeoptionschanged?.                        Invoke (Options, Format, bitmap);                    Break                        Case BarcodeFormat.EAN_8:var Ean8_writer = new Zxing.barcodewriter (); Ean8_writer.format = Barcodeformat.                        Ean_8;                        Ean8_writer.options = Options;                        Bitmap = Ean8_writer.write (TbxBarcodeValue.Text.Trim ()); Barcodeoptionschanged?.                        Invoke (Options, Format, bitmap);                    Break                        Case BarcodeFormat.CODE_39:var Code39_writer = new Zxing.barcodewriter ();                        Code39_writer.format = barcodeformat.code_39;                        Code39_writer.options = Options;                        Bitmap = Code39_writer.write (TbxBarcodeValue.Text.Trim ()); Barcodeoptionschanged?.                        Invoke (Options, Format, bitmap);                    Break                        Case BarcodeFormat.UPC_A:var Upca_writer = new Zxing.barcodewriter ();                        Upca_writer.format = barcodeformat.upc_a;                        Upca_writer.options = Options;     Bitmap = Upca_writer.write (TbxBarcodeValue.Text.Trim ());                   Barcodeoptionschanged?.                        Invoke (Options, Format, bitmap);                    Break                        Case BarcodeFormat.UPC_E:var Upce_writer = new Zxing.barcodewriter ();                        Upce_writer.format = barcodeformat.upc_e;                        Upce_writer.options = Options;                        Bitmap = Upce_writer.write (TbxBarcodeValue.Text.Trim ()); Barcodeoptionschanged?.                        Invoke (Options, Format, bitmap);                    Break                        Case BarcodeFormat.MSI:var Msi_writer = new Zxing.barcodewriter ();                        Msi_writer.format = Barcodeformat.msi;                        Msi_writer.options = Options;                        Bitmap = Msi_writer.write (TbxBarcodeValue.Text.Trim ()); Barcodeoptionschanged?.                        Invoke (Options, Format, bitmap);                    Break                   Case BARCODEFORMAT.ITF:     var itf_writer = new Zxing.barcodewriter ();                        Itf_writer.format = BARCODEFORMAT.ITF;                        Itf_writer.options = Options;                        Bitmap = Itf_writer.write (TbxBarcodeValue.Text.Trim ()); Barcodeoptionschanged?.                        Invoke (Options, Format, bitmap);                    Break                        Case BarcodeFormat.PLESSEY:var Plessey_writer = new Zxing.barcodewriter ();                        Plessey_writer.format = Barcodeformat.plessey;                        Plessey_writer.options = Options;                        Bitmap = Plessey_writer.write (TbxBarcodeValue.Text.Trim ()); Barcodeoptionschanged?.                        Invoke (Options, Format, bitmap);                    Break                        Case BarcodeFormat.MAXICODE:var Code_writer = new Zxing.barcodewriter ();                        Code_writer.format = Barcodeformat.maxicode; Code_writer.options = Options;                        Bitmap = Code_writer.write (TbxBarcodeValue.Text.Trim ()); Barcodeoptionschanged?.                        Invoke (Options, Format, bitmap);                    Break Default:throw New Exception ("barcode format temporarily not supported!                "); } #endregion} catch (Exception ex) {MessageBox.Show ("code generation Error: "+ ex."            Message, "system hint", MessageBoxButtons.OK, Messageboxicon.error);            } finally {pbxbarcode.image = bitmap; }

  

zxing. NET multiple Barcode format generation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.