Friday, September 19, 2014

Qr code Generator with c#


QR code (abbreviated from Quick Response Code) is first designed for the  automotive industry in Japan. A barcode is a machine-readable optical label that contains information about the item to which it is attached. A QR code uses four standardized encoding modes (numeric, alphanumeric, byte / binary) to efficiently store data.

      I am going to show how to encode and decode a message in QR code by using the qr code library. The qr code library provides a pre-defined functions to encode and decode a message. Moreover the qr code library contains binaries for developing windows form applications, asp .Net web application and windows phone application also.

Now I am going to show the demo of qr code generation process by using simple windows form application

Input (Encode tab):



Output (Decode tab):


Encode Source Code:

 private void button1_Click(object sender, EventArgs e)
        {
            string errorType = comboBox2.SelectedText;
            //select the error correction level
            if (errorType == "Low")
            {
                encoder.ErrorCorrectionLevel = ErrorCorrectionLevel.L;
            }
            else if (errorType == "Medium Low")
            {
                encoder.ErrorCorrectionLevel = ErrorCorrectionLevel.M;
            }
            else if (errorType == "Medium High") 
            {
                encoder.ErrorCorrectionLevel = ErrorCorrectionLevel.Q;
            }
            else if (errorType == "High")
            {
                encoder.ErrorCorrectionLevel = ErrorCorrectionLevel.H;
            }
            //set the width and height for the qr code
            encoder.Width = Int32.Parse(txtwidth.Text);
            encoder.Height=Int32.Parse(txtheight.Text);
            pictureBox1.Image = encoder.Encode(BarcodeFormat.QRCode, textBox1.Text);
        }

Decode Source Code:
 

private void button4_Click(object sender, EventArgs e)
        {
            Dictionary<DecodeOptions, object> decodingOptions = new Dictionary<DecodeOptions, object>(); 
           //add the decoding options
            decodingOptions.Add(DecodeOptions.AutoRotate, true);
            //load the qr code into bitmap
            Bitmap bmp = new Bitmap(textBox4.Text);
            Result result = decoder.Decode(bmp, decodingOptions);
            if (result != null)
            {
                textBox2.Text = result.Text;
            }

        }

Download the complete source code from here.


Previous Blog: ocr with c#

Happy coding !!!



3 comments:

  1. Hello There. I found your blog using msn. This is an extremely well written article. I will be sure to bookmark it and return to read more of your useful information. Thanks for the post. I’ll certainly comeback.
    qr code generator online

    ReplyDelete
  2. This post is to assist advertisers with contacting more crowd utilizing QR codes. Figure out how to make your own, and how you can enlarge the opportunity of purchasers examining them. These are the strides to making your QR code and a beginning to contacting more crowd. QR Code Creator

    ReplyDelete
  3. Thanks for the blog post buddy! Keep them coming... z code system discount

    ReplyDelete