There are three ways of doing this:
1, Zxing.net
Example Source:
protected voidPage_Load (Objectsender, EventArgs e) {DateTime Dtbegin=DateTime.Now; stringFileName = AppDomain.CurrentDomain.BaseDirectory +"bin\\"+ Guid.NewGuid (). ToString () +". jpg"; stringContent = Httputility.urldecode ( This. request["content"]); Barcodewriter writer=NewBarcodewriter () {Format=Barcodeformat.qr_code, Options=Newencodingoptions () {Width= -, Height= -}, Renderer= (ibarcoderenderer<bitmap>) activator.createinstance (typeof(Bitmaprenderer))}; Bitmap BMP=writer. Write (content); Bmp. Save (FileName); This. Response.WriteFile (FileName); stringTime = (DateTime.Now-dtbegin). Totalmilliseconds.tostring (); }
View Code
2, Qrcode.net
Example Source:
protected voidPage_Load (Objectsender, EventArgs e) {DateTime Dtbegin=DateTime.Now; stringFileName = AppDomain.CurrentDomain.BaseDirectory +"bin\\"+ Guid.NewGuid (). ToString () +". jpg"; stringContent = Httputility.urldecode (request.querystring["content"]); Qrencoder Qrencoder=NewQrencoder (ERRORCORRECTIONLEVEL.M); QRCode QRCode=Qrencoder.encode (content); Graphicsrenderer renderer=NewGraphicsrenderer (NewFixedmodulesize (5, Quietzonemodules.two), Brushes.black, brushes.white); using(FileStream stream =NewFileStream (FileName, FileMode.Create)) {renderer. WriteToStream (Qrcode.matrix, Imageformat.png, stream); } This. Response.WriteFile (FileName); stringSpendtime = (DateTime.Now-dtbegin). Totalmilliseconds.tostring (); }
View Code
3, Thoughtworks.qrcode
Example Source:
protected voidPage_Load (Objectsender, EventArgs e) {DateTime Dtbegin=DateTime.Now; stringContent = Httputility.urldecode (request.querystring["content"]); Bitmap Bitmap=Createqrcode (content); stringFileName = AppDomain.CurrentDomain.BaseDirectory +"bin\\"+ Guid.NewGuid (). ToString () +". jpg"; Bitmap. Save (FileName, imageformat.jpeg); Response.WriteFile (FileName,true); stringSpendtime = (DateTime.Now-dtbegin). Totalmilliseconds.tostring (); } PublicBitmap Createqrcode (stringcontent) {Qrcodeencoder Qrencoder=NewQrcodeencoder (); Qrencoder.qrcodeencodemode=Qrcodeencoder.encode_mode. BYTE; Qrencoder.qrcodescale=4;//Convert.ToInt32 (txtsize.text);Qrencoder.qrcodeversion =7;//Convert.ToInt32 (cboversion.selectedvalue);Qrencoder.qrcodeerrorcorrect =qrcodeencoder.error_correction. M Try{Bitmap QRCode=Qrencoder.encode (content, Encoding.UTF8); returnQRCode; } Catch(IndexOutOfRangeException ex) {//exceeding the capacity limit of the current QR code version, please select a higher QR code version return NewBitmap ( -, -); } Catch(Exception ex) {//error generating QR code return NewBitmap ( -, -); } }
View Code
Precautions:
1. One way to request QR code on the Web is to assign the service page generating the QR code to the SRC attribute of .
2, three ways are open source projects, the use of the official website to download the source code, and add to the project can be
3, three way comparison: 3 processing speed is the fastest, in the web-side access processing time is probably 20ms,1 and 2 speed of not much, 50ms to 70ms or so, but 1 and 2dll smaller, hundreds of K, and 3 is 6M
4, Mode 3 of the demo run a problem, cause unknown origin
Two-dimensional code generation and decoding