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


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹(shù)的示例代碼(圣誕
- 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
- 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語(yǔ)言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 01-10C#通過(guò)反射獲取當(dāng)前工程中所有窗體并
- 01-10關(guān)于ASP網(wǎng)頁(yè)無(wú)法打開(kāi)的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
- 01-10WinForm實(shí)現(xiàn)仿視頻播放器左下角滾動(dòng)新
- 01-10C#停止線程的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#通過(guò)重寫(xiě)Panel改變邊框顏色與寬度的
- 01-10C#實(shí)現(xiàn)讀取注冊(cè)表監(jiān)控當(dāng)前操作系統(tǒng)已
隨機(jī)閱讀
- 01-10SublimeText編譯C開(kāi)發(fā)環(huán)境設(shè)置
- 01-10delphi制作wav文件的方法
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 01-11Mac OSX 打開(kāi)原生自帶讀寫(xiě)NTFS功能(圖文
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
- 04-02jquery與jsp,用jquery
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載


