How to generate a QR code barcode as a PNG file using C# in .NET Framework

QR codes are the most robust type of barcode, with a variety of useful applications in advertising, web design, and even POS systems. Today we will be looking at how to quickly generate QR codes from any text string. To keep things simple, let’s skip the heavy coding and use an API. To do this, we will need to first install the API client by pasting this command into your Package Manager console:

Install-Package Cloudmersive.APIClient.NET.Barcode -Version 1.2.4

Then call GenerateBarcodeQRCode and provide it with a string to be encoded.

using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NET.Barcode.Api;
using Cloudmersive.APIClient.NET.Barcode.Client;
using Cloudmersive.APIClient.NET.Barcode.Model;
namespace Example
{
public class GenerateBarcodeQRCodeExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");
var apiInstance = new GenerateBarcodeApi();
var value = value_example; // string | QR code text to convert into the QR code barcode
try
{
// Generate a QR code barcode as a PNG file, a type of 2D barcode which can encode free-form text information
System.IO.Stream result = apiInstance.GenerateBarcodeQRCode(value);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling GenerateBarcodeApi.GenerateBarcodeQRCode: " + e.Message );
}
}
}
}

Your output will be a PNG image file. For example here is the output for “The quick brown fox jumps over the lazy dog.”

Image for post
Image for post

Easy. If you need other barcode related functionality, this API also allows barcode lookups and is able to generate UPC and EAN type barcodes as well.

Image for post
Image for post

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store