Barcodes
ZXing.net
  • Add to project using NuGet. From the Package Manager Console: Install-Package ZXing.Net

Use as follows:

using System.Windows.Media.Imaging;  // For BitmapSource, PngBitmapEncoder
using ZXing;
using BarcodeWriter = ZXing.Presentation.BarcodeWriter;
using BarcodeWriterGeometry = ZXing.Presentation.BarcodeWriterGeometry;
...
public static void CreateBarcode()
{
    var writer = new BarcodeWriter
    {
        Format = BarcodeFormat.CODE_39,
        Options = new ZXing.Common.EncodingOptions { Height = 50, Width = 200, Margin = 0, PureBarcode = false }
    };
    WriteableBitmap wbBarcode = writer.Write("13-123456");
    SaveToPng(wbBarcode.Clone(), System.IO.Path.Combine(System.IO.Path.GetTempPath(), "barcode.png"));
}
///----------------------------------------------------------------------------------------
private static void SaveToPng(BitmapSource imgSource, string dstFilename)
{
    if (dstFilename != string.Empty)
    {
        using (System.IO.FileStream streamDstImage = new System.IO.FileStream(
            dstFilename, System.IO.FileMode.Create))
        {
            PngBitmapEncoder encDstImage = new PngBitmapEncoder();
            encDstImage.Frames.Add(BitmapFrame.Create(imgSource));
            encDstImage.Save(streamDstImage);
            streamDstImage.Close();
        }
    }
}
BarcodeLib
  • Add to project using NuGet. From the Package Manager Console: Install-Package BarcodeLib

Use as follows:

public static void CreateBarcode()
{
    BarcodeLib.Barcode barcode = new BarcodeLib.Barcode()
    {
        IncludeLabel   = true,
        Alignment      = BarcodeLib.AlignmentPositions.CENTER,
        Width          = 200,
        Height         = 50,
        RotateFlipType = System.Drawing.RotateFlipType.RotateNoneFlipNone,
        BackColor      = System.Drawing.Color.White,
        ForeColor      = System.Drawing.Color.Black,
    };
 
    System.Drawing.Image img = barcode.Encode(BarcodeLib.TYPE.CODE128B, "13-123456");
    img.Save(System.IO.Path.Combine(System.IO.Path.GetTempPath(), "barcode.png"));
}