Write 1-BPP Barcodes Images
A 1bpp image is a monochrome image that can display only two colors, typically black and white. Each pixel in the picture is represented by a single bit, where "0" may represent black and "1" may represent white, or vice versa. This format is best suited for scenarios where speed and accuracy are essential, and it is intended to be read by machines. In this code example, we will demonstrate how to convert the barcode we created into a 1bpp image for maximum contrast and reliability when scanning.
5-Step Guide to Converting Barcodes into 1BPP Barcode Images
- using IronBarCode;
- var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8);
- myBarcode.SaveAs1BppBitmap("1bppImage.bmp");
- var byteData = myBarcode.To1BppBinaryData();
- var anyBitmap = myBarcode.To1BppImage();
Code Explanation
We first import the IronBarcode library, then we generate a barcode using the BarcodeWriter.CreateBarcode
method. We pass two variables to the method: the string value and the type of the barcode. In the example above, these are "12345" and "EAN8", respectively.
After creating the barcode, we can call the save method SaveAs1BppBitmap
and pass it a file name. Doing this saves the barcode as a 1bpp bitmap with the name being the file name it's saved as.
Aside from saving it directly to a Bitmap, there are also alternative save methods. IronBarcode supports saving the barcode as 1bpp binary data using the To1BppBinaryData
method. Converting to binary data allows you to pass the variable as binary data to other sections of the application or integrate with existing code bases. Furthermore, IronBarcode also supports saving the barcode as a 1-bit-per-pixel (1bpp) image using the To1BppImage
method.
For more examples, check the How-to Guide on using IronBarcode with C#.