How could I encode my string into a QR Code using ZXing.Net?
I can already decode, but having problems in encoding. It has an error that says: no encoder available for format AZTEC.
Here is my code:
IBarcodeWriter writer = new BarcodeWriter();
Bitmap barcodeBitmap;
var result = writer.Encode("Hello").ToBitmap();
barcodeBitmap = new Bitmap(result);
pictureBox1.Image = barcodeBitmap;
You don't fully initialize the BarcodeWriter. You have to set the barcode format.
Try the following code snippet:
IBarcodeWriter writer = new BarcodeWriter { Format = BarcodeFormat.QR_CODE };
var result = writer.Write("Hello");
var barcodeBitmap = new Bitmap(result);
pictureBox1.Image = barcodeBitmap;
@dizzytri99er
Seems that I have sucessfully encoded a message with ZXing.net therefore I think it does support Aztec encoding
This is the code I have used;
static void Main(string[] args)
{
IBarcodeWriter writer = new BarcodeWriter
{
Format = BarcodeFormat.AZTEC
};
Bitmap aztecBitmap;
var result = writer.Write("I love you ;)");
aztecBitmap = new Bitmap(result);
using (var stream = new FileStream("test.bmp", FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
var aztecAsBytes = ImageToByte(aztecBitmap);
stream.Write(aztecAsBytes, 0, aztecAsBytes.Length);
}
}
public static byte[] ImageToByte(Image img)
{
ImageConverter converter = new ImageConverter();
return (byte[])converter.ConvertTo(img, typeof(byte[]));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With