C#使用第三方組件生成二維碼匯總
用C#如何生成二維碼,我們可以通過現(xiàn)有的第三方dll直接來實(shí)現(xiàn),下面列出幾種不同的生成方法:
1.通過QrCodeNet(Gma.QrCodeNet.Encoding.dll)來實(shí)現(xiàn)
1.1):首先通過VS2015的NuGet下載對應(yīng)的第三方組件,如下圖所示:
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"); } }
更多詳細(xì)信息請參考如下鏈接:
http://qrcodenet.codeplex.com/
http://stackoverflow.com/questions/7020136/free-c-sharp-qr-code-generator
2.通過ThoughtWorks.QRCode(ThoughtWorks.QRCode.dll)來實(shí)現(xiàn)
1.1):首先通過VS2015的NuGet下載對應(yīng)的第三方組件,如下圖所示:
1.2):具體生成二維碼方法如下
private void GenerateQRByThoughtWorks() { QRCodeEncoder encoder = new QRCodeEncoder(); encoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;//編碼方式(注意:BYTE能支持中文,ALPHA_NUMERIC掃描出來的都是數(shù)字) encoder.QRCodeScale = 4;//大小(值越大生成的二維碼圖片像素越高) encoder.QRCodeVersion = 0;//版本(注意:設(shè)置為0主要是防止編碼的字符串太長時發(fā)生錯誤) encoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;//錯誤效驗(yàn)、錯誤更正(有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)來實(shí)現(xiàn)
1.1):首先通過VS2015的NuGet下載對應(yīng)的第三方組件,如下圖所示:
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"); }
更多詳細(xì)信息請參考如下鏈接:
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)來實(shí)現(xiàn)
下載對應(yīng)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"); }
我們使用的是試用版(帶水印的......),還有付費(fèi)的正版,詳情請參考如下鏈接:
http://www.barcodelib.com/asp_net/
欄 目:C#教程
下一篇:c# 實(shí)現(xiàn)輪詢算法實(shí)例代碼
本文標(biāo)題:C#使用第三方組件生成二維碼匯總
本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6133.html
您可能感興趣的文章
- 01-10C#使用Dispose模式實(shí)現(xiàn)手動對資源的釋放
- 01-10C#3.0使用EventLog類寫Windows事件日志的方法
- 01-10C#使用windows服務(wù)開啟應(yīng)用程序的方法
- 01-10c# ArrayList的使用方法小總結(jié)
- 01-10C#使用ADO.Net部件來訪問Access數(shù)據(jù)庫的方法
- 01-10C#使用Mutex簡單實(shí)現(xiàn)程序單實(shí)例運(yùn)行的方法
- 01-10使用Nopcommerce為商城添加滿XX減XX優(yōu)惠券功能
- 01-10C#中yield用法使用說明
- 01-10C#編程和Visual Studio使用技巧(下)
- 01-10C#編程和Visual Studio使用技巧(上)


閱讀排行
本欄相關(guān)
- 01-10C#通過反射獲取當(dāng)前工程中所有窗體并
- 01-10關(guān)于ASP網(wǎng)頁無法打開的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
- 01-10WinForm實(shí)現(xiàn)仿視頻 器左下角滾動新
- 01-10C#停止線程的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#通過重寫Panel改變邊框顏色與寬度的
- 01-10C#實(shí)現(xiàn)讀取注冊表監(jiān)控當(dāng)前操作系統(tǒng)已
隨機(jī)閱讀
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 01-10delphi制作wav文件的方法
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 04-02jquery與jsp,用jquery
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 01-11ajax實(shí)現(xiàn)頁面的局部加載