C# 二维码的生成
2021-06-19 10:09
标签:rect wing private black modules form mem one 二维码 nuget 搜索qrcodenet,然后选择下载gma.qrcodenet public partial class Form1 : Form private void button1_Click(object sender, EventArgs e) public static Bitmap ToQR(String url) GraphicsRenderer render = new GraphicsRenderer(new FixedModuleSize(5, QuietZoneModules.Two), Brushes.Black, Brushes.White); render.Draw(g, qrCode.Matrix); return pic; private void GenerateQRByQrCodeNet() GraphicsRenderer renderer = new GraphicsRenderer(new FixedModuleSize(5, QuietZoneModules.Two), Brushes.Black, Brushes.White); string strbaidu = "http://www.baidu.com"; using (MemoryStream ms = new MemoryStream(be)) C# 二维码的生成 标签:rect wing private black modules form mem one 二维码 原文地址:https://www.cnblogs.com/tangyanzhi1111/p/10281953.html
{
public Form1()
{
InitializeComponent();
}
{
//GenerateQRByQrCodeNet();
pictureBox1.Image = ToQR("http://www.baidu.com");
}
{
QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.M);
QrCode qrCode = qrEncoder.Encode(url);
DrawingSize size = render.SizeCalculator.GetSize(qrCode.Matrix.Width);
Bitmap pic = new Bitmap(size.CodeWidth, size.CodeWidth);
Graphics g = Graphics.FromImage(pic);
}
{
QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
QrCode qrCode = new QrCode();
qrEncoder.TryEncode("hello this is test application encode", out qrCode);
byte[] be = Encoding.Default.GetBytes(strbaidu);
{
renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, ms);
Image img = Image.FromStream(ms);
pictureBox1.Image = img;
//img.Save("D:/csharp-qrcode-net.png");
}
}
}