Add a QR code to your website using asp.net

Sometimes a QR code is the easiest way to direct people to your website. QR codes can be used in many ways.

  • QR code on your restaurant table to open a menu
  • QR code on an electoral campaign postcard to open more information about a candidate
  • QR code to open the playbill for a play
  • QR code to show that a ticket is paid for

And many more. The URL for the intended target is embedded in the QR code. To get started, add the QRcoder class library at the top of you code and then add a variable, fileDirectory to define where you want to store the QR png file after is is created. You are creating a png file that you can print and give to your users.

using QRCoder;

Here is the code to create the QR code.

  // create qr code;
                    String qrText = "https://example.com" 
                    QRCodeGenerator qrGenerator = new QRCodeGenerator();
                    QRCodeData qrCodeData = qrGenerator.CreateQrCode(qrText, QRCodeGenerator.ECCLevel.Q);
                    QRCode qrCode = new QRCode(qrCodeData);
                    System.Drawing.Bitmap qrCodeImage = qrCode.GetGraphic(20);
                    System.IO.File.WriteAllBytes(fileDirectory + @"\qr_myexample.png", BitmapToBytes(qrCodeImage));
 

The user of your QR code just points the camera of his phone at the QR code and the URL will pop up for him to click on. Some older phone users may need to install a QR code reader.

Leave a Reply

Your email address will not be published. Required fields are marked *