C# ZXing.Net 在CF中将字符串编码为二维码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13289742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 08:05:03  来源:igfitidea点击:

ZXing.Net Encode string to QR Code in CF

c#compact-frameworkzxing

提问by SleepNot

How could I encode my string into a QR Code using ZXing.Net?

如何使用ZXing.Net 将我的字符串编码为二维码?

I can already decode, but having problems in encoding. It has an error that says: no encoder available for format AZTEC.

我已经可以解码了,但是编码有问题。它有一个错误说:没有可用于格式 AZTEC 的编码器

Here is my code:

这是我的代码:

IBarcodeWriter writer = new BarcodeWriter();
Bitmap barcodeBitmap;
var result = writer.Encode("Hello").ToBitmap();
barcodeBitmap = new Bitmap(result);
pictureBox1.Image = barcodeBitmap;

采纳答案by Michael

You don't fully initialize the BarcodeWriter. You have to set the barcode format.

您没有完全初始化 BarcodeWriter。您必须设置条形码格式。

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;

回答by dizzytri99er

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 encoderand Zbar

二维码编码器Zbar

回答by lixonn

@dizzytri99er

@dizzytri99er

Seems that I have sucessfully encoded a message with ZXing.net therefore I think it does support Aztec encoding

似乎我已经成功地使用 ZXing.net 编码了一条消息,因此我认为它确实支持 Aztec 编码

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