C#使用第三方组件生成二维码汇总
用c#如何生成二维码,我们可以通过现有的第三方dll直接来实现,下面列出几种不同的生成方法:
1.通过qrcodenet(gma.qrcodenet.encoding.dll)来实现
1.1):首先通过vs2015的nuget下载对应的第三方组件,如下图所示:
1.2):具体生成二维码方法如下
private void generateqrbyqrcodenet() { qrencoder qrencoder = new qrencoder(errorcorrectionlevel.h); qrcode qrcode = new qrcode(); qrencoder.tryencode("hello world. this is eric sun testing...", out qrcode); graphicsrenderer renderer = new graphicsrenderer(new fixedmodulesize(5, quietzonemodules.two), brushes.black, brushes.white); using (memorystream ms = new memorystream()) { renderer.writetostream(qrcode.matrix, imageformat.png, ms); image img = image.fromstream(ms); img.save("e:/csharp-qrcode-net.png"); } }
更多详细信息请参考如下链接:
http://qrcodenet.codeplex.com/
http://*.com/questions/7020136/free-c-sharp-qr-code-generator
2.通过thoughtworks.qrcode(thoughtworks.qrcode.dll)来实现
1.1):首先通过vs2015的nuget下载对应的第三方组件,如下图所示:
1.2):具体生成二维码方法如下
private void generateqrbythoughtworks() { qrcodeencoder encoder = new qrcodeencoder(); encoder.qrcodeencodemode = qrcodeencoder.encode_mode.byte;//编码方式(注意:byte能支持中文,alpha_numeric扫描出来的都是数字) encoder.qrcodescale = 4;//大小(值越大生成的二维码图片像素越高) encoder.qrcodeversion = 0;//版本(注意:设置为0主要是防止编码的字符串太长时发生错误) encoder.qrcodeerrorcorrect = qrcodeencoder.error_correction.m;//错误效验、错误更正(有4个等级) encoder.qrcodebackgroundcolor = color.yellow; encoder.qrcodeforegroundcolor = color.green; string qrdata = "hello 世界! this is eric sun testing...."; bitmap bcodebitmap = encoder.encode(qrdata.tostring()); bcodebitmap.save(@"e:\helloworld.png", imageformat.png); bcodebitmap.dispose(); }
3):通过spire.barcode(spire.barcode.dll)来实现
1.1):首先通过vs2015的nuget下载对应的第三方组件,如下图所示:
1.2):具体生成二维码方法如下
private void generateqrbyspire() { barcodesettings bs = new barcodesettings() { data = "this is qr code.", type = barcodetype.qrcode, toptextcolor = color.red, showchecksumchar = false, showtext = false }; //generate the barcode based on the this.barcodecontrol1 barcodegenerator generator = new barcodegenerator(bs); image barcode = generator.generateimage(); //save the barcode as an image barcode.save(@"e:\barcode-2d.png"); }
1.3):附加具体生成条形码方法如下
private void generatebarcodebyspire() { barcodesettings bs = new barcodesettings() { data = "this is barcode.", showchecksumchar = false, toptextcolor = color.red, showtoptext = false, showtextonbottom = true }; //generate the barcode based on the this.barcodecontrol1 barcodegenerator generator = new barcodegenerator(bs); image barcode = generator.generateimage(); //save the barcode as an image barcode.save(@"e:\barcode.png"); }
更多详细信息请参考如下链接:
http://freebarcode.codeplex.com/
http://www.e-iceblue.com/knowledgebase/spire.barcode/program-guide/programme-guide-for-spire.barcode.html
3.通过barcodelib(barcodelib.barcode.asp.net.dll)来实现
下载对应dll的连接为 http://www.barcodelib.com/asp_net/
4.1):具体生成二维码方法如下
private void generateqrbybarcodelib() { qrcode qrbarcode = new qrcode(); qrbarcode.encoding = qrcodeencoding.auto; qrbarcode.data = "336699885522 this is eric sun testing."; qrbarcode.modulesize = 10; qrbarcode.leftmargin = 8; qrbarcode.rightmargin = 8; qrbarcode.topmargin = 8; qrbarcode.bottommargin = 8; qrbarcode.imageformat = system.drawing.imaging.imageformat.gif; // save qr code barcode image into your system qrbarcode.drawbarcode("e:/csharp-qrcode-lib.gif"); }
4.2):附加具体生成条形码方法如下
private void generatelinearbybarcodelib() { linear barcode = new linear(); barcode.type = barcodetype.code128; barcode.data = "code128"; // other barcode settings. // save barcode image into your system barcode.drawbarcode("e:/barcode.png"); }
我们使用的是试用版(带水印的......),还有付费的正版,详情请参考如下链接:
http://www.barcodelib.com/asp_net/