写入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();
代码解释
We first import the IronBarcode library, then we generate a barcode using the BarcodeWriter.CreateBarcode method. 我们向该方法传递两个变量:字符串值和条形码类型。 在上面的例子中,它们分别是"12345"和"EAN8"。
After creating the barcode, we can call the save method SaveAs1BppBitmap and pass it a file name. 这样做会将条形码保存为 1bpp 位图,名称即为保存的文件名。
除了直接保存为位图之外,还有其他保存方法。 IronBarcode supports saving the barcode as 1bpp binary data using the To1BppBinaryData method. 转换为二进制数据后,您可以将变量作为二进制数据传递给应用程序的其他部分,或者与现有代码库集成。 Furthermore, IronBarcode also supports saving the barcode as a 1-bit-per-pixel (1bpp) image using the To1BppImage method.





