Example code written by C # zxing two-dimensional code

Source: Internet
Author: User
private void Button1_Click (object sender, EventArgs e) {if (string. IsNullOrEmpty (This.textBox1.Text.Trim ())) {MessageBox.Show ("Please enter the information you need to convert!")                ");            Return            The string content = TextBox1.Text;               Hashtable hints= new Hashtable (); Hints. ADD (Encodehinttype.error_correction, ERRORCORRECTIONLEVEL.L);//error correction level hints. ADD (Encodehinttype.character_set, "UTF-8");//encoding format Bytematrix Bytematrix = new Multiformatwriter (). Encode (Conten            T, Barcodeformat.qr_code, +, hints);            Bitmap Bitmap = Tobitmap (Bytematrix);            pictureBox1.Image = bitmap;            SaveFileDialog SFD = new SaveFileDialog ();            Sfd.filter = "*.png|*.png";            Sfd.addextension = true; try {if (sfd.showdialog () = = DialogResult.OK) {WriteToFile (b  Ytematrix, System.Drawing.Imaging.ImageFormat.Png, sfd.filename);              }} catch (Exception ex) {MessageBox.Show (ex).            Message); }} public static void WriteToFile (Bytematrix matrix, System.Drawing.Imaging.ImageFormat format, string file            ) {System.Drawing.Imaging.EncoderParameters EPS = new System.Drawing.Imaging.EncoderParameters (); Eps.            Param[0] = new System.Drawing.Imaging.EncoderParameter (System.Drawing.Imaging.Encoder.Quality, 100L);            Bitmap bmap = Tobitmap (matrix); Bmap.        Save (file, format); } public static Bitmap Tobitmap (Bytematrix matrix) {int width = matrix.            Width; int height = matrix.            Height;            Bitmap bmap = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);                    for (int x = 0; x < width; + +) {for (int y = 0; y < height; y++) { Bmap. SetPixel (x, Y, Matrix.get_renamEd (x, y)! =-1?            Colortranslator.fromhtml ("Purple"): colortranslator.fromhtml ("0xFFFFFFFF"));//can customize color and background colors}}             return bmap; }


More example code written by C # zxing Two-dimensional code related articles please follow topic.alibabacloud.com!

  • Related Article

    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.