SleepNot
SleepNot

Reputation: 3038

ZXing.Net Encode string to QR Code in CF

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;

Upvotes: 11

Views: 44739

Answers (3)

Michael
Michael

Reputation: 2496

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;

Upvotes: 33

lixonn
lixonn

Reputation: 1063

@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[]));
    }

Upvotes: 2

dizzytri99er
dizzytri99er

Reputation: 930

could it possibly be the size of the codes your are scanning?

take a look here

best way to generate and encode QR codes would be...

QR code encoder and Zbar

Upvotes: 0

Related Questions