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:
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.
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.
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.
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"); } } }
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.
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.