Original: http://blog.csdn.net/kongwei521/article/details/17588825
First effect:
1: First Download BarcodeLib.dll http://pan.baidu.com/share/link?shareid=2590968386&uk=2148890391&fid=1692834292 If it does not exist, search for the download yourself.
1.barcodelib.dll One-dimensional barcode library supports the following barcode formats
Upc-a
Upc-e
UPC 2 Digit Ext.
UPC 5 Digit Ext.
EAN-13
JAN-13
EAN-8
ITF-14
Codabar
PostNet
Bookland/isbn
Code 11
Code 39
Code Extended
Code 93
Logmars
Msi
Interleaved 2 of 5
Standard 2 of 5
Code 128
Code 128-a
Code 128-b
Code 128-c
Telepen
Then add a reference to the project
Private voidButton6_click (Objectsender, EventArgs e) {System.Drawing.Image Image; intwidth =148, height = -; stringFilesavepath = AppDomain.CurrentDomain.BaseDirectory +"barcodepattern.jpg"; if(File.exists (Filesavepath)) File.delete (Filesavepath); Getbarcode (height, width, BarcodeLib.TYPE.CODE128,"20131025-136", outimage, Filesavepath); pictureBox1.Image= Image.FromFile ("barcodepattern.jpg"); } Public Static voidGetbarcode (intHeightintwidth, Barcodelib.type TYPE,stringCode outSystem.Drawing.Image Image,stringFilesaveurl) { Try{image=NULL; Barcodelib.barcode b=NewBarcodelib.barcode (); B.backcolor= System.Drawing.Color.White;//Picture background colorB.forecolor = System.Drawing.Color.Black;//Barcode ColorB.includelabel =true; B.alignment=BarcodeLib.AlignmentPositions.LEFT; B.labelposition=BarcodeLib.LabelPositions.BOTTOMCENTER; B.imageformat= System.Drawing.Imaging.ImageFormat.Jpeg;//Picture FormatSystem.Drawing.Font Font =NewSystem.Drawing.Font ("Verdana", 10f);//font SettingsB.labelfont =font; B.height= height;//Picture height setting (px units)B.width = Width;//Picture width setting (px units)Image= B.encode (type, code);//Create a pictureimage. Save (Filesaveurl, System.Drawing.Imaging.ImageFormat.Jpeg); } Catch(Exception ex) {image=NULL; } }
Simply write it. Go to http://www.barcodelib.com/net_barcode/main.html to see it in detail.
Use Zxing.dll to generate barcodes and QR codes http://zxingnet.codeplex.com/
ZXing (zebracrossing) is an open source, support multi-format barcode image processing library. Using this kind of library can easily realize the generation and resolution of two-dimensional code image.
Download zxing.dll Project reference Reference
{multiformatwriter Mutiwriter=NewCom.google.zxing.MultiFormatWriter (); Bytematrix BM= Mutiwriter.encode (Txtmsg.text, Com.google.zxing.BarcodeFormat.QR_CODE, -, -); Bitmap img=BM. Tobitmap (); pictureBox1.Image=img; //automatically save pictures to current directory stringfilename = System.Environment.CurrentDirectory +"\\QR"+ DateTime.Now.Ticks.ToString () +". jpg"; Img. Save (filename, System.Drawing.Imaging.ImageFormat.Jpeg); Lbshow. Text="the picture has been saved to:"+filename; } Catch(Exception ee) {MessageBox.Show (EE. Message); }
use QrCodeNet.dll to generate barcodes and QR codes http://qrcodenet.codeplex.com/
Download QrCodeNet.dll Project Reference Reference
Private voidButton2_Click (Objectsender, EventArgs e) { varCodeparams = Codedescriptor.init (ErrorCorrectionLevel.H, TextBox1.Text.Trim (), Quietzonemodules.two,5); Codeparams.tryencode (); //Render The QR code as an image using(varms =NewMemoryStream ()) {Codeparams.render (MS); Image Image=Image.fromstream (MS); pictureBox1.Image=image; if(Image! =NULL) Picturebox1.sizemode= Image. Height > Picturebox1.height?PictureBoxSizeMode.Zoom:PictureBoxSizeMode.Normal; } }/// <summary> ///Class containing the description of the QR code and wrapping encoding and rendering./// </summary> Internal classCodedescriptor { Publicerrorcorrectionlevel Ecl; Public stringContent; Publicquietzonemodules Quietzones; Public intmodulesize; PublicBitmatrix Matrix; Public stringContentType;/// <summary> ///Parse QueryString that define the QR code properties/// </summary> /// <param name= "Request" >HttpRequest containing HTTP GET data</param> /// <returns>A QR Code Descriptor Object</returns> Public StaticCodedescriptor Init (Errorcorrectionlevel level,stringContent, Quietzonemodules Qzmodules,intmodulesize) { varCP =Newcodedescriptor ();////Error correction levelCp. ECL =Level ;////Code content to encodeCp. Content =content;////Size of the quiet zoneCp. Quietzones =Qzmodules;////Module SizeCp. Modulesize =modulesize;returnCP;} /// <summary> ///Encode the content with desired parameters and save the generated Matrix/// </summary> /// <returns>True If the encoding succeeded, false if the content is empty or too large to fit in a QR code</returns> Public BOOLTryencode () {varEncoder =NewQrencoder (ECL); QRCode QR; if(!encoder. Tryencode (Content, outqr)) return false; Matrix=qr. Matrix; return true; } /// <summary> ///Render the Matrix as a PNG image/// </summary> /// <param name= "MS" >MemoryStream to store the image bytes into</param> Internal voidRender (MemoryStream ms) {varRender =NewGraphicsrenderer (Newfixedmodulesize (Modulesize, quietzones)); Render. WriteToStream (Matrix, System.Drawing.Imaging.ImageFormat.Png, MS); ContentType="Image/png"; } }
Effect:
Reference Address:
Http://www.cnblogs.com/mzlee/archive/2011/03/19/Lee_Barcode.html
http://blog.163.com/smxp_2006/blog/static/588682542010215163803/
http://q.cnblogs.com/q/15253/
Http://www.csharpwin.com/csharpspace/13364r9803.shtml
Http://www.2cto.com/kf/201304/203035.html
C # generates barcodes using BarcodeLib.dll (one-dimensional, zxing,qrcodenet/dll QR code)