How to Create a QR Code as an Image
Creating a QR code as an image involves generating a visual representation of a QR code, which encodes data (such as a URL, text, or other information) in a two-dimensional matrix composed of black and white squares. These squares can be scanned and decoded by a camera or QR code reader.
How to Create a QR Code as an Image
- Download the C# library to create QR code as an image
- Create the QR code as an object
- Use the Save method to obtain the AnyBitmap
- Use the SaveAs method to export to an image file
- Explore the various supported formats
Start using IronQR in your project today with a free trial.
Create QR Code as Images
Creating a QR code with IronQR is very simple. You only need one line of code to create the QR code as an object. To export the QR code as an image, use the Save
method followed by the SaveAs
method.
:path=/static-assets/qr/content-code-examples/how-to/create-qr-code-image.cs
// Using QRCoder Library
using QRCoder;
using System;
using System.Drawing;
using System.Drawing.Imaging;
// Main entry point of the program
class Program
{
static void Main()
{
// Input text to encode in the QR Code
string data = "12345";
// Create an instance of QRCodeGenerator
using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
{
// Create the QR Code data
QRCodeData qrCodeData = qrGenerator.CreateQrCode(data, QRCodeGenerator.ECCLevel.Q);
// Generate the QR Code as a bitmap
using (QRCode qrCode = new QRCode(qrCodeData))
{
// Create the bitmap based on the QR Code data, with scale 20
using (Bitmap qrCodeImage = qrCode.GetGraphic(20))
{
// Save the QR Code as a PNG file
qrCodeImage.Save("simpleQrCode.png", ImageFormat.Png);
// Inform that the file has been saved
Console.WriteLine("QR Code generated and saved as 'simpleQrCode.png'.");
}
}
}
}
}
' Using QRCoder Library
Imports QRCoder
Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
' Main entry point of the program
Friend Class Program
Shared Sub Main()
' Input text to encode in the QR Code
Dim data As String = "12345"
' Create an instance of QRCodeGenerator
Using qrGenerator As New QRCodeGenerator()
' Create the QR Code data
Dim qrCodeData As QRCodeData = qrGenerator.CreateQrCode(data, QRCodeGenerator.ECCLevel.Q)
' Generate the QR Code as a bitmap
Using qrCode As New QRCode(qrCodeData)
' Create the bitmap based on the QR Code data, with scale 20
Using qrCodeImage As Bitmap = qrCode.GetGraphic(20)
' Save the QR Code as a PNG file
qrCodeImage.Save("simpleQrCode.png", ImageFormat.Png)
' Inform that the file has been saved
Console.WriteLine("QR Code generated and saved as 'simpleQrCode.png'.")
End Using
End Using
End Using
End Sub
End Class

The Save
method returns an AnyBitmap object. With this object, we can export to various image formats, such as:
- JPEG (.jpg or .jpeg): JPEG is a commonly used compressed format for digital photos. It uses lossy compression, reducing file size while maintaining acceptable quality.
- PNG (.png): PNG is a lossless image format ideal for web use. It supports transparency and retains high quality without data loss.
- Bmp (.bmp): The Bitmap format is an uncompressed raster image format used primarily on Windows platforms. It retains high-quality images but produces large file sizes.
- GIF (.gif): GIF supports animations and transparency but is limited to 256 colors. It is widely used for simple web graphics and short animations.
- TIFF (.tiff or .tif): TIFF is a flexible format used for high-quality images, often in professional photography. It can be lossless or compressed.
- WBMP (.wbmp): WBMP is a monochrome format used in wireless communication. If unsupported, it defaults to BMP.
- WebP (.webp): WebP is a modern image format that provides excellent compression (both lossy and lossless), making it ideal for the web.
- Icon (.ico): Icon format stores small square images used as icons for programs or files, commonly in operating systems.
- WMF (.wmf): WMF is a vector and raster image format used primarily on Windows. It is often used for graphics in legacy systems.
- RawFormat (.raw): Raw format refers to unprocessed image data, typically used in digital photography. It retains maximum quality and is used by professionals for image editing.
Supported QR Code Types
Multiple types of QR codes are supported for both creation and reading. Below are the supported QR code types:
- QRCode: This is the standard QR code most commonly used today. It can store a significant amount of data (up to 7,089 numeric characters or 4,296 alphanumeric characters), making it suitable for a wide range of applications, from website URLs to contact information.

- MicroQRCode: The Micro QR Code is a smaller version of the standard QR code, designed for situations where space is limited. It can store less data than a standard QR code (up to 35 numeric characters or 21 alphanumeric characters), but its compact size makes it ideal for applications where a standard QR code would be too large, such as on small packaging or tiny printed labels.

- RMQRCode: RMQR Code (Rectangular Micro QR Code) is another compact version of the QR code but in a rectangular shape rather than a square. This version allows for flexibility in its aspect ratio, which can be useful for applications where a rectangular space is available. It can store data similar to the Micro QR Code but is designed for specific use cases where the available space is non-square.

Frequently Asked Questions
What is a QR code?
A QR code, or Quick Response code, is a type of matrix barcode that encodes information into a two-dimensional pattern of black and white squares. It can be scanned and interpreted by cameras and QR code readers.
How can I generate a QR code image in C#?
To create a QR code as an image in C#, you can use the IronQR library. First, download the library from NuGet. Then, create a QR code object with your desired data, such as a URL, and use the 'Save' and 'SaveAs' methods to export it to an image format like PNG or JPEG.
What image formats are supported for exporting QR codes?
IronQR supports multiple image formats for exporting QR codes, including JPEG, PNG, BMP, GIF, TIFF, WBMP, WebP, Icon, WMF, and RawFormat.
What is the difference between standard and compact QR codes?
A QRCode is the standard QR code that can store a large amount of data, while a MicroQRCode is a smaller version designed for limited space situations, storing less data but being more compact.
What is an AnyBitmap object used for?
An AnyBitmap object in IronQR is the result of saving a QR code using the 'Save' method. It can be used to export the QR code to various image formats.
How do I export a QR code to a PNG file?
To convert a QR code to a PNG file using IronQR, first create a QR code object, then save it to an AnyBitmap object. Use the 'SaveAsPng' method to export the AnyBitmap to a PNG file.
Can URLs be encoded into QR codes?
Yes, IronQR can create QR codes for URLs. Simply pass the URL as a string to the QRCodeWriter's 'CreateQrCode' method.
What is a rectangular version of a QR code?
An RMQRCode, or Rectangular Micro QR Code, is a compact version of the QR code with a rectangular shape, allowing for aspect ratio flexibility, suitable for non-square spaces.
Is transparency supported in QR code images?
Yes, by exporting the QR code as a PNG, which supports transparency, you can create a QR code with transparent backgrounds using IronQR.
Why use WebP format for QR code images?
WebP is a modern image format that offers excellent compression, both lossy and lossless, making it ideal for web use due to its reduced file size and maintained quality.