Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
The Quick Response Code, or QR code, has its roots in the Japanese car sector. It is also known as the QR Symbol, QR Graphic, or QR Code Graphic. Masahiro Hara created it in 1994, and its initial application was as a quick and easy tool to monitor the progress of vehicles as they were being assembled in factories. Since then, the use of QR codes as a barcode substitute has grown significantly outside the car manufacturing industry. Its greater reading speed and storage capacity are to blame for this. QR codes can be used to exchange and store information for marketing purposes and for social media sites and accounts in addition to tracking and identifying products. The static QR code which is generated from the application can be scanned with the camera application.
With IronBarcode's QR Code Library, creating dynamic QR codes is simple. With just a few lines of code, this straightforward library can quickly create a QR code. IronBarcode can generate QR codes with high quality, and it makes it easy for the QR Code scanner to read custom codes.
The proceeding sections of this article present an example to demonstrate how easily our library generates QR codes.
Open Visual Studio and click the File menu option for New Project.
Click Next after selecting the Console App template in the ensuing box.
Enter any project name you choose (for instance, QR Code Generator) in the Project name text area, and then enter the location of the new project in the Location field. Click the Next button to proceed after that.
Select a Dot NET Framework (here, we're using Dot NET 6.0 (Long term support)) from the Framework drop-down option, then click Create.
Download the necessary IronBarcode library by entering the code below into the package manager :
Install-Package BarCode
Alternatively, we can conduct a search using the NuGet package management and download the "IronBarcode" package, which will list all results and allow us to choose the one we need to download.
IronBarcode allows us to create QR code with few lines of code. Use the QRCodeWriter.CreateQrCode
method to create a new QR code as shown in the following code:
using IronBarCode;
QRCodeWriter.CreateQrCode("www.google.com", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium,0).SaveAsPng("NewQR.png");
using IronBarCode;
QRCodeWriter.CreateQrCode("www.google.com", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium,0).SaveAsPng("NewQR.png");
Imports IronBarCode
QRCodeWriter.CreateQrCode("www.google.com", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium,0).SaveAsPng("NewQR.png")
The data to be encoded in the code image (which might be a URL or a Stream) is the only mandatory parameter for the CreateQrCode
method. Additionally, the method takes three optional parameters:
CreateQrCode
method by default uses the highest level of correction (QRCodeWriter.QrErrorCorrectionLevel.Highest
).The sample above uses the medium level of error correction to produce a 500 by 500 pixel graphic that creates a custom QR code. Next, we can save the generated QR codes as a PNG file at a specified file location by calling the SaveAsPng
method.
We'll then look at an example of a use-case where a user or business wants to add a company logo to a generated QR code. To accomplish this, the QrCodeWriter.CreateQrCodeWithLogo
method is used in the example code below.
var QRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("www.gogle.com","qrWithlogo.png",500);
QRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkRed);
QRWithLogo.SaveAsPng("NewQR_Code.png");
var QRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("www.gogle.com","qrWithlogo.png",500);
QRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkRed);
QRWithLogo.SaveAsPng("NewQR_Code.png");
Dim QRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("www.gogle.com","qrWithlogo.png",500)
QRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkRed)
QRWithLogo.SaveAsPng("NewQR_Code.png")
In the above example, we encoded the String value of the URL "www.google.com" into a new QR code that embeds an image from that website into a given file location.
Graphics are included in the QR code above. The logo is automatically positioned to that size and sized to match the QR code square grid so that the pure code can still be read. We can also customize the color of the QR address bar code using the ChangeBarCodeColor
method, which offers a range of code colors we can use on the QR code. One uses Color-class-types, while the other makes use of HTML hex color notation as follows:
QRWithLogo.ChangeBarCodeColor(System.Drawing.ColorTranslator.FromHtml("#8B0000"));
QRWithLogo.ChangeBarCodeColor(System.Drawing.ColorTranslator.FromHtml("#8B0000"));
QRWithLogo.ChangeBarCodeColor(System.Drawing.ColorTranslator.FromHtml("#8B0000"))
The above line of code specifies the dark red color of the barcode. Then, as the code instructs, we save it as a PNG file. We can also save QR codes in other file formats such as HTML:
QRWithLogo.SaveAsHtmlFile("test.html");
QRWithLogo.SaveAsHtmlFile("test.html");
QRWithLogo.SaveAsHtmlFile("test.html")
The outcome of the source code above is displayed in the image below.
QR codes can be saved in other file formats such as HTML:
QRWithLogo.SaveAsHtmlFile("test.html");
QRWithLogo.SaveAsHtmlFile("test.html");
QRWithLogo.SaveAsHtmlFile("test.html")
IronBarcode can be used in web applications as well. The MVC Dot Net core 6.0 sample code is provided below.
public IActionResult Index()
{
var barcode = QRCodeWriter.CreateQrCode("www.google.com", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium, 0);
barcode.SaveAsPng("Barcode.png");
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "Barcode.png");
return PhysicalFile(filePath, "image/png", "Barcode.png");
}
public IActionResult Index()
{
var barcode = QRCodeWriter.CreateQrCode("www.google.com", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium, 0);
barcode.SaveAsPng("Barcode.png");
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "Barcode.png");
return PhysicalFile(filePath, "image/png", "Barcode.png");
}
Public Function Index() As IActionResult
Dim barcode = QRCodeWriter.CreateQrCode("www.google.com", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium, 0)
barcode.SaveAsPng("Barcode.png")
Dim filePath = Path.Combine(Directory.GetCurrentDirectory(), "Barcode.png")
Return PhysicalFile(filePath, "image/png", "Barcode.png")
End Function
The code that we used for the Windows/console program is the same as the one that is provided above. The above code first generates a QR code file before returning it. Then QR code can be downloaded by the user as PNG file. We can also make it available for use on mobile devices and online forms.
For more code tutorials for IronBarcode click here.
One of the most effective libraries for creating and identifying barcodes is IronBarcode. Additionally, it is among the quickest libraries for creating and reading barcodes. Different operating systems are compatible with the library.
It is simple to develop and supports a wide range of barcode formats. We can alter the color, line width, height, barcode text, and more.
You may find the licensing information here. Both a free QR code generator library for developer license and a premium edition of IronBarcode are available. It includes free support and updates for a year.
Users can also benefit from Iron Suite, a Suite of 5 professional ASP.NET core libraries including IronBarcode, IronXL, IronPDF and more.
9 .NET API products for your office documents