我已经创建了一个应用程序,它为我生成了一个带有ZXing库的二维码图像,但它使用的是版本3的二维码,我想知道是否可以将其更改为版本10……我是ZXing库的新手……
代码如下:
public void CreateQRImage(string inputData)
{
if (radioRH.Checked)
{
if (inputData.Trim() == String.Empty)
{
System.Windows.Forms.MessageBox.Show("Data must not be empty.");
}
BarcodeWriter qrcoder = new ZXing.BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new ZXing.QrCode.QrCodeEncodingOptions
{
ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.H,
Height = 250,
Width = 250
}
};
string tempFileName = System.IO.Path.GetTempPath() + inputData + ".png";
Image image;
String data = inputData;
var result = qrcoder.Write(inputData);
image = new Bitmap(result);
image.Save(tempFileName);
System.Diagnostics.Process.Start(tempFileName);
var textRes = qrcoder.Write(inputData);
int textWidth = 230, textHeight = 20;
// creating new bitmap having imcreased width
var img = new Bitmap(textRes.Width + textWidth, textRes.Height);
using (var g = Graphics.FromImage(img))
using (var font = new Font(FontFamily.GenericMonospace, 14))
using (var brush = new SolidBrush(Color.Black))
using (var bgBrush = new SolidBrush(Color.White))
using (var format = new StringFormat() { Alignment = StringAlignment.Near })
{
// filling background with white color
g.FillRectangle(bgBrush, 0, 0, img.Width, img.Height);
// drawing the generated image over new one
g.DrawImage(textRes, new Point(0, 0));
// drawing text
g.DrawString(inputData, font, brush, textRes.Width, (result.Height - textHeight) / 2, format);
}
img.Save(tempFileName);
}我希望二维码图像从这个(版本3)更改

到这个(版本10)

发布于 2019-04-15 12:51:36
我知道这是一个老问题,但我最近也遇到了同样的问题。
我的公司要求我生成版本4的二维码(33 * 33),但Zxing默认使用更低的版本。
这在网上几乎没有记录,但有一种方法可以迫使Zxing生成特定版本的二维码。在您的代码示例中,只需在格式选项中添加"QrVersion = 10“:
BarcodeWriter qrcoder = new ZXing.BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new ZXing.QrCode.QrCodeEncodingOptions
{
ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.H,
Height = 250,
Width = 250,
QrVersion = 10
}
};这将产生一个版本10的二维码。
**注意:如果您设置了较低的QrVersion值(例如4),然后尝试在二维码中放入大量数据,则会抛出错误。
https://stackoverflow.com/questions/30080243
复制相似问题