QRCoder是一个简单的生成二维码的库,用C#.NET编写,他是开源的MIT-license。
//WIFI二维码 //WiFi generator = new WiFi("My-WiFis-Name", "s3cr3t-p4ssw0rd", WiFi.Authentication.WPA); //string payload = generator.ToString(); //邮件二维码 //Mail generator = new Mail("[email protected]", "Look at this!", "Hi John, have a look at this QRCoder library!"); //string payload = generator.ToString(); //网址 //Url generator = new Url("https://github.com/codebude/QRCoder/"); //string payload = generator.ToString(); //电话 //PhoneNumber generator = new PhoneNumber("+491701234567"); //string payload = generator.ToString(); //普通字符串的二维码 string payload = "第一张二维码图片"; QRCodeGenerator qRCodeGenerator = new QRCodeGenerator(); QRCodeData qRCodeData = qRCodeGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); QRCode qRCode = new QRCode(qRCodeData); Bitmap bitmap = qRCode.GetGraphic(20); //有图标的二维码 //Bitmap bitmap = qRCode.GetGraphic(20, Color.Black, Color.White, (Bitmap)Bitmap.FromFile(@"D:\1612181843.png")); bitmap.Save($@"D:\{Environment.TickCount}.png", System.Drawing.Imaging.ImageFormat.Png); //释放资源 bitmap.Dispose(); qRCode.Dispose(); qRCodeData.Dispose(); qRCodeGenerator.Dispose();
原文地址:https://www.cnblogs.com/zhao123/p/10972681.html
时间: 2024-10-16 15:19:18