Nuget管理包添加 BarcodeLib
代码实现:
/// <summary>
/// 生成条形码
/// </summary>
/// <param name="width">条形码的宽度</param>
/// <param name="height">条形码的高度</param>
/// <param name="content">条形码内容</param>
/// <returns></returns>
public static Image GenerateBarCodeBitmap(int width,int height, string content)
{
using (var barcode = new Barcode()
{
IncludeLabel = true,
Alignment = AlignmentPositions.CENTER,
Width = width,
Height = height,
RotateFlipType = RotateFlipType.RotateNoneFlipNone,
BackColor = Color.White,
ForeColor = Color.Black,
})
{
return barcode.Encode(TYPE.CODE128B, content);
}
}