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
ZXing.Net Encode string to QR Code in CF
提问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
回答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[]));
}

