Style Barcode

In IronBarcode, you have the flexibility to resize barcodes, add margins, change colors, and save them in various popular file formats. Furthermore, you can adjust the DPI settings to achieve finer control over the detail of the image.

// Import the IronBarCode library
using IronBarCode;

public class BarcodeExample
{
    public static void Main()
    {
        // Create a BarcodeWriter instance to generate a QR code
        var barcodeWriter = new BarcodeWriter()
        {
            Format = BarcodeEncoding.QRCode,
            Content = "https://example.com"
        };

        // Customize the barcode's appearance
        barcodeWriter.ResizeTo(500, 500); // Set width and height to 500 pixels
        barcodeWriter.ChangeBarColor(System.Drawing.Color.Blue); // Change the bar color to blue
        barcodeWriter.ChangeBackgroundColor(System.Drawing.Color.LightGray); // Change background color to light gray

        // Save the barcode to a file
        barcodeWriter.SaveAsPng("example_qrcode.png");

        // Optional: Adjust the DPI (dots per inch) for more detailed images
        barcodeWriter.ResizeToDPI(300); // Set the barcode DPI to 300
    }
}
// Import the IronBarCode library
using IronBarCode;

public class BarcodeExample
{
    public static void Main()
    {
        // Create a BarcodeWriter instance to generate a QR code
        var barcodeWriter = new BarcodeWriter()
        {
            Format = BarcodeEncoding.QRCode,
            Content = "https://example.com"
        };

        // Customize the barcode's appearance
        barcodeWriter.ResizeTo(500, 500); // Set width and height to 500 pixels
        barcodeWriter.ChangeBarColor(System.Drawing.Color.Blue); // Change the bar color to blue
        barcodeWriter.ChangeBackgroundColor(System.Drawing.Color.LightGray); // Change background color to light gray

        // Save the barcode to a file
        barcodeWriter.SaveAsPng("example_qrcode.png");

        // Optional: Adjust the DPI (dots per inch) for more detailed images
        barcodeWriter.ResizeToDPI(300); // Set the barcode DPI to 300
    }
}
' Import the IronBarCode library
Imports IronBarCode

Public Class BarcodeExample
	Public Shared Sub Main()
		' Create a BarcodeWriter instance to generate a QR code
		Dim barcodeWriter As New BarcodeWriter() With {
			.Format = BarcodeEncoding.QRCode,
			.Content = "https://example.com"
		}

		' Customize the barcode's appearance
		barcodeWriter.ResizeTo(500, 500) ' Set width and height to 500 pixels
		barcodeWriter.ChangeBarColor(System.Drawing.Color.Blue) ' Change the bar color to blue
		barcodeWriter.ChangeBackgroundColor(System.Drawing.Color.LightGray) ' Change background color to light gray

		' Save the barcode to a file
		barcodeWriter.SaveAsPng("example_qrcode.png")

		' Optional: Adjust the DPI (dots per inch) for more detailed images
		barcodeWriter.ResizeToDPI(300) ' Set the barcode DPI to 300
	End Sub
End Class
$vbLabelText   $csharpLabel
  • Import the IronBarcode Library: The script starts by importing the required IronBarCode library, which provides the necessary classes and methods to create and manipulate barcodes.
  • Create a Barcode Writer Instance: BarcodeWriter is initialized with specific properties like Format (to determine the type of barcode) and Content (the data to encode).
  • Customize the Barcode's Appearance: Various methods allow modification of the barcode's size and colors:

    • ResizeTo(500, 500): Resizes the barcode to 500x500 pixels.
    • ChangeBarColor: Alters the color of the bars in the barcode.
    • ChangeBackgroundColor: Changes the background color.
  • Save the Barcode to a File: The barcode is saved as a PNG file using SaveAsPng.\
  • Adjust the DPI for Detailed Images: Using ResizeToDPI(300), the DPI is set to 300, refining the image detail.