我想使用ZXing(0.16.4)创建一个QR码,但遇到了以下异常:
以下是我的代码:
使用.Net Framework 4.6.1的几乎相同的代码可以正常工作。System.InvalidOperationException:“必须设置渲染器实例。”
以下是我的代码:
static void Main(string[] args)
{
var qrCode = CreateQrCode("test");
Console.ReadKey();
}
public static byte[] CreateQrCode(string content)
{
BarcodeWriter<Bitmap> writer = new BarcodeWriter<Bitmap>
{
Format = BarcodeFormat.QR_CODE,
Options = new QrCodeEncodingOptions
{
Width = 100,
Height = 100,
}
};
var qrCodeImage = writer.Write(content); // BOOM!!
using (var stream = new MemoryStream())
{
qrCodeImage.Save(stream, ImageFormat.Png);
return stream.ToArray();
}
}