IRONSOFTWAREHOME
写入1-BPP条形码图片
using IronBarCode;

var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8);

myBarcode.SaveAs1BppBitmap("1bppImage.bmp");
var byteData = myBarcode.To1BppBinaryData();
var anyBitmap = myBarcode.To1BppImage();
Imports IronBarCode

Dim myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8)

myBarcode.SaveAs1BppBitmap("1bppImage.bmp")
Dim byteData = myBarcode.To1BppBinaryData()
Dim anyBitmap = myBarcode.To1BppImage()
NuGet Download
PM > Install-Package BarCode
写入1-BPP条形码图片

写入1-BPP条形码图片

1bpp 图像是一种单色图像,只能显示两种颜色,通常是黑色和白色。图像中的每个像素都由一个比特表示,其中"0"可以代表黑色,"1"可以代表白色,反之亦然。 这种格式最适合对速度和准确性要求很高的场景,并且是为机器读取而设计的。 在此代码示例中,我们将展示如何将我们创建的条码转换为1bpp图像,以实现扫描时的最大对比度和可靠性。

将条形码转换为 1BPP 条形码图像的 5 步指南

  • using IronBarCode;
  • var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8);
  • myBarcode.SaveAs1BppBitmap("1bppImage.bmp");
  • var byteData = myBarcode.To1BppBinaryData();
  • var anyBitmap = myBarcode.To1BppImage();

代码解释

我们先导入IronBarcode库,然后使用BarcodeWriter.CreateBarcode方法生成条形码。 我们向该方法传递两个变量:字符串值和条形码类型。 在上面的示例中,分别是"12345"和EAN8

在创建条形码之后,我们可以调用SaveAs1BppBitmap并传入文件名。 这样做会将条形码保存为1bpp Bitmap,文件名就是它被保存的文件名。

除了直接保存到Bitmap,还有其他替代保存方法。 IronBarcode支持使用To1BppBinaryData方法将条形码保存为1bpp二进制数据。 转换为二进制数据后,您可以将变量作为二进制数据传递给应用程序的其他部分,或者与现有代码库集成。 此外,IronBarcode还支持使用To1BppImage方法将条形码保存为1-bit-per-pixel (1bpp) 图像。

在 GitHub 上查看

准备开始了吗?

Nuget Downloads 2,422,100版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户