Ultimate List of QR Code SDK Features - ByteScout
  • Home
  • /
  • Blog
  • /
  • Ultimate List of QR Code SDK Features

Ultimate List of QR Code SDK Features

The ByteScout QR Code SDK is a one-stop solution for generating QR codes. This SDK features API level granularity giving immense power in the hand of the users as well as simple GUI based drag-n-drop design. This SDK can be used to generate QR Codes and barcodes from both images and PDFs.

Here are some of the key features of this software:

1. Read QR codes from an image

The ByteScout QR code SDK integrates with your system seamlessly. As a programmer, you’re simply one step away from generating a QR code from an image. Using C#, you can get it done by writing only 10-15 lines of code.

So, here are the steps involved from opening the SDK to generating the QR code. The same can be done using other languages like JavaScript or VB.Net. First of all open any IDE of your preference.

QR code SDK

For example, Visual Studio opens a similar editor to the image above.

Once the editor shows up, simply type in the following lines of code in the editor.

using System.Diagnostics;
using Bytescout.BarCode;

namespace GeneralExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create and activate QRCode instance
            using (QRCode barcode = new QRCode())
            {
                barcode.RegistrationName = "demo";
                barcode.RegistrationKey = "demo";

                // Set value            
               barcode.Value = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 1234567890";

                // Uncomment if you don't need margins
                // barcode.Margins = new Margins(0, 0, 0, 0);
                // barcode.DrawQuietZones = false;

                // Save barcode image to file
                barcode.SaveImage("result.png");
            }

            // Open the image in default image viewer (for demo purpose)
            Process.Start("result.png");
        }
    }
}

The code is pretty intuitive as it’s short and straightforward. First, it imports the necessary libraries including the Bytescout.BarCode module. Next, inside the main, you’re specifying all the paths and values. Reminder: be sure to change the path values to match the path (absolute or relative) of the files in your machine. The same goes for the output directory where the image is going to be stored.

2. Convert vCard to QR Code

Haven’t heard about vCards? No worries, you will know about it by the end of this section. So, simply put, vCard (aka Virtual Contact File, VCF) is the go-to file format for storing and transferring contact information and business cards. So, why do I need to convert a vCard to a QR code in the first place? Simple, because it’s always easier to send and receive an image.

The following example uses an external .NET vCard library made by David Pinch. In order to convert an instance of a vCard to a QR code, simply use the following code. Like before, we import the necessary libraries first. A vCard instance has been created manually right from scratch in this example. In case you already have a vCard (in most of the cases) that you want to convert to a QR code, the task becomes even simpler.

using System.Diagnostics;
using System.Drawing.Imaging;
using System.IO;
using Bytescout.BarCode;
using Thought.vCards;

namespace GenerateVCardQRCode
{
    /// 




<summary>
   /// This example demonstrates generation of QR Code encoded vCard.
    /// It uses vCard library by David Pinch:
    /// 
    /// vCard Class Library for .NET (Version 0.4; LGPL license)
    /// Copyright (c) 2007-2009 David Pinch 
    /// http://www.thoughtproject.com/Libraries/vCard/
    /// 
    /// </summary>





    class Program
    {
        static void Main(string[] args)
        {
            // Generate vCard
            vCard vCard = new vCard();
            vCard.GivenName = "Forrest";
            vCard.FamilyName = "Gump";
            vCard.Organization = "Bubba Gump Shrimp Co.";
            vCard.Title = "Shrimp Man";
            vCard.Phones.Add(new vCardPhone("(111) 555-1212", vCardPhoneTypes.Home));
            vCard.EmailAddresses.Add(new vCardEmailAddress("forrestgump@example.com", vCardEmailAddressType.Internet));

           vCardDeliveryAddress address = new vCardDeliveryAddress();

address.AddressType.Add(vCardDeliveryAddressTypes.Home);
address.Street = "100 Waters Edge";
address.City = "Baytown";
address.Region = "LA";
           	address.PostalCode = "30314";
           	address.Country = "United States of America";
           	vCard.DeliveryAddresses.Add(address);

           	// Save vCard data to string
vCardStandardWriter writer = new vCardStandardWriter();
           	StringWriter stringWriter = new StringWriter();
           	writer.Write(vCard, stringWriter);

           // Create and activate Bytescout.Barcode.QRCode instance
using (QRCode barcode = new QRCode("demo", "demo"))
            {
                // Set barcode value
                barcode.Value = stringWriter.ToString();
                // Save barcode to image
barcode.SaveImage("result.png", ImageFormat.Png);
            }

            // Open generated barcode image in default associated application 
            Process.Start("result.png");
        }
    }
}

You instantiate StringWriter that is going to be used for setting the Value property of the QRCode object. Finally, you save the QRCode object as an image and optionally open it using an image viewer.

3. Create color QR code

Bored of the classic black on the white combination? Are you a trendsetter? Maybe, both? Fear not, ByteScout QR code SDK lets you create QR codes that are going be less of an eyesore.

As it can be seen from the attached code snippet, you simply need to specify the BackColor and ForeColor properties of the QRCode object in order to create a colorful QR code. The rest of the code stays the same.

using System.Diagnostics;
using System.Drawing;
using Bytescout.BarCode;

namespace ColoredQRCode
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create and activate QRCode instance
            using (QRCode barcode = new QRCode())
            {
                barcode.RegistrationName = "demo";
                barcode.RegistrationKey = "demo";

                // Set background color
                barcode.BackColor = Color.Yellow;
                // Set foreground color
                barcode.ForeColor = Color.Red;

                // Set value            
                barcode.Value = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 1234567890";

                // Save barcode to image
                barcode.SaveImage("result.png");
            }

            // Open the image in default image viewer (for demo purpose)
            Process.Start("result.png");
        }
    }
}

4. Create a QR Code with binary data

Here’s another addition to the existing features. Up until now, we’ve only seen alphanumeric values that are being stored in the QR code. But apart from them, we can also store binary data in the form of a QR code.

using System.Diagnostics;
using System.Text;
using Bytescout.BarCode;

namespace QRCodeWithBinaryData
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create and activate QRCode component instance
            using (QRCode barcode = new QRCode())
            {
                barcode.RegistrationName = "demo";
                barcode.RegistrationKey = "demo";

                // Sample byte array to use as value 
                byte[] byteArray = new byte[] { 0, 10, 11, 12, 13, 14, 15, 0xFF };

// Set value by converting byte array to string
barcode.Value = Encoding.ASCII.GetString(byteArray);

                // Save barcode image
                barcode.SaveImage("result.png");

// Open the image in default associated application (for the demo purpose)
                Process.Start("result.png");
            }
        }
    }
}

We have used a byte array to store 8 values that are going to be encoded into the QR code. And finally, the ASCII encoding is used to decode all the bytes in the specified byte array into a string to assign to the Value property of the QRCode instance.

4. Create GS1 QR Code

Another advanced yet handy feature is the GS1 QR code generation tool. The GS1 QR code is a variant of the QR code that conforms to the GS1 specifications. So, what is it for? A GS1 QR code is used specifically for carrying extra information such as the lot number, quantity, etc. in addition to the usual information.

using System.Diagnostics;
using Bytescout.BarCode;

namespace GS1QRCode
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create and activate QRCode instance
            using (QRCode barcode = new QRCode())
            {
                barcode.RegistrationName = "demo";
                barcode.RegistrationKey = "demo";

                // Enable generation of GS1 version of QR Code
                barcode.IsGS1 = true;

                // Set value that is formatted according to GS1 specification
                barcode.Value = "(01)07046261398572(17)130331(10)TEST5632(21)19067811811";

                // Save barcode image to file
                barcode.SaveImage("result.png");
            }

            // Open the image in default image viewer (for demo purpose)
            Process.Start("result.png");
        }
    }
}

Switching to the GS1 version and creating a GS1 QR Code is just a single step away. You simply need to set the IsGS1 property of the QRCode instance that you are dealing with. And that’s it – done! It’s that simple.

5. Other QR Code features

  • QR code specifications. Other than the settings mentioned above, you can also tweak some of the slightly advanced settings such as Error Correction Level and Encoding hints. The Error Correction Level of your QRCode instance can be specified easily by setting the QROption_ErrorCorrectionLevel property of the QR code. As you’d realize by going through the documentation, this property can be set explicitly to any of the 4 values: Low, Medium, Quarter, and High. Higher the level, the more it tries to recover the codewords. In the High level, it can recover up to 30% of the codewords, for example.
    The Encoding hint can be set similarly. To specify the Encoding hint for your QRCode instance, simply specify the QROption_EncodingHint property of the QR code. This property has only 2 associated values: 0 (Mode8, every non-alphanumeric character is encoded as they are) and 1 (Kanji, Japanese characters are encoded as Shif-JIS characters).
  • A variety of different image formats – The ByteScout QR Code SDK supports, by default, many different image formats. The format that it supports includes PNG, JPEG, TIFF, BMP, and GIF for reading and writing tasks.
  • No internet is needed – Unlike most of the other SDKs, ByteScout QR code SDK works completely offline i.e. once the software is installed you would not usually need the internet. All of the features are available offline.
  • Technical support – The SDK is paired with excellent customer support and rich and easy to understand documentation. The documentation includes easy to follow command clarification as well as example source codes.
   

About the Author

ByteScout Team ByteScout Team of Writers ByteScout has a team of professional writers proficient in different technical topics. We select the best writers to cover interesting and trending topics for our readers. We love developers and we hope our articles help you learn about programming and programmers.  
prev
next