Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
In this tutorial, we explore the process of creating barcodes as streams in C# using the Iron Barcode library. Assuming Iron Barcode is installed on your machine, we dive straight into the coding process by importing the Iron Barcode namespace in our Program.cs
file. The tutorial demonstrates how to create a barcode containing the URL of Iron Barcode using the Data Matrix encoding scheme. Once the barcode is created, it is converted and exported into various formats such as JPEG, PNG, TIFF, GIF, and PDF using the methods provided by Iron Barcode. Additionally, the barcode is converted to a default stream if no specific format is specified. The tutorial concludes by running the program and successfully generating and exporting the barcodes. Users are encouraged to explore the extensive functionalities offered by Iron Barcode and to subscribe for more tutorials or try Iron Software through a trial subscription.
Here's a sample implementation in C#:
// Import the IronBarcode namespace to allow barcode generation
using IronBarCode;
class Program
{
static void Main(string[] args)
{
// Create a Barcode with a Data Matrix encoding scheme
var barcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.DataMatrix);
// Export barcode to a JPEG stream
using (var jpegStream = barcode.ToStream(BarcodeEncoding.JPEG))
{
// Stream is ready to be used as needed, e.g., saving to a file or uploading
}
// Export barcode to a PNG stream
using (var pngStream = barcode.ToStream(BarcodeEncoding.PNG))
{
// Stream is ready to be used as needed
}
// Export barcode to a TIFF stream
using (var tiffStream = barcode.ToStream(BarcodeEncoding.TIFF))
{
// Stream is ready to be used as needed
}
// Export barcode to a GIF stream
using (var gifStream = barcode.ToStream(BarcodeEncoding.GIF))
{
// Stream is ready to be used as needed
}
// Export barcode to a PDF stream
using (var pdfStream = barcode.ToStream(BarcodeEncoding.PDF))
{
// Stream is ready to be used as needed
}
// Handling a case where no specific format is specified
using (var defaultStream = barcode.ToStream())
{
// Default stream handling, e.g., exporting in standard image format
}
}
}
// Import the IronBarcode namespace to allow barcode generation
using IronBarCode;
class Program
{
static void Main(string[] args)
{
// Create a Barcode with a Data Matrix encoding scheme
var barcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.DataMatrix);
// Export barcode to a JPEG stream
using (var jpegStream = barcode.ToStream(BarcodeEncoding.JPEG))
{
// Stream is ready to be used as needed, e.g., saving to a file or uploading
}
// Export barcode to a PNG stream
using (var pngStream = barcode.ToStream(BarcodeEncoding.PNG))
{
// Stream is ready to be used as needed
}
// Export barcode to a TIFF stream
using (var tiffStream = barcode.ToStream(BarcodeEncoding.TIFF))
{
// Stream is ready to be used as needed
}
// Export barcode to a GIF stream
using (var gifStream = barcode.ToStream(BarcodeEncoding.GIF))
{
// Stream is ready to be used as needed
}
// Export barcode to a PDF stream
using (var pdfStream = barcode.ToStream(BarcodeEncoding.PDF))
{
// Stream is ready to be used as needed
}
// Handling a case where no specific format is specified
using (var defaultStream = barcode.ToStream())
{
// Default stream handling, e.g., exporting in standard image format
}
}
}
' Import the IronBarcode namespace to allow barcode generation
Imports IronBarCode
Friend Class Program
Shared Sub Main(ByVal args() As String)
' Create a Barcode with a Data Matrix encoding scheme
Dim barcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.DataMatrix)
' Export barcode to a JPEG stream
Using jpegStream = barcode.ToStream(BarcodeEncoding.JPEG)
' Stream is ready to be used as needed, e.g., saving to a file or uploading
End Using
' Export barcode to a PNG stream
Using pngStream = barcode.ToStream(BarcodeEncoding.PNG)
' Stream is ready to be used as needed
End Using
' Export barcode to a TIFF stream
Using tiffStream = barcode.ToStream(BarcodeEncoding.TIFF)
' Stream is ready to be used as needed
End Using
' Export barcode to a GIF stream
Using gifStream = barcode.ToStream(BarcodeEncoding.GIF)
' Stream is ready to be used as needed
End Using
' Export barcode to a PDF stream
Using pdfStream = barcode.ToStream(BarcodeEncoding.PDF)
' Stream is ready to be used as needed
End Using
' Handling a case where no specific format is specified
Using defaultStream = barcode.ToStream()
' Default stream handling, e.g., exporting in standard image format
End Using
End Sub
End Class
Further Reading: How to Export Barcodes as Streams