通过C#生成二维码
private void btnCreate_Click(object sender, EventArgs e)
{
if (txtEncodeData.Text.Trim() == String.Empty)
{
MessageBox.Show("Data must not be empty.");
return;
}
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
String encoding = cboEncoding.Text;
if (encoding == "Byte")
{
qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
}
else if (encoding == "AlphaNumeric")
{
qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC;
}
else if (encoding == "Numeric")
{
qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.NUMERIC;
}
try
{
int scale = Convert.ToInt16(txtSize.Text);
qrCodeEncoder.QRCodeScale = scale;
}
catch (Exception ex)
{
MessageBox.Show("Invalid size!");
return;
}
try
{
int version = Convert.ToInt16(cboVersion.Text);
qrCodeEncoder.QRCodeVersion = version;
}
catch (Exception ex)
{
MessageBox.Show("Invalid version !");
}
string errorCorrect = cboCorrectionLevel.Text;
if (errorCorrect == "L")
qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L;
else if (errorCorrect == "M")
qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
else if (errorCorrect == "Q")
qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.Q;
else if (errorCorrect == "H")
qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;
try
{
Image image;
String data = txtEncodeData.Text;
image = qrCodeEncoder.Encode(data, Encoding.Default);
pb_view.Image = image;
}
catch (Exception exe)
{
MessageBox.Show("你输入的文字过多!请删减些文字,或更高的版本。国内高版本很多软件不支持。请慎用!在此声明,做违法犯等问题本人没任何责任,此软件免费使用。");
return;
}
}
评论