1. Specify a logo image to generate
Must refer to ThoughtWorks.QRCode.dll
Qrcodewechart QWC =NewQrcodewechart (); // intMemberID =1000000; // intOrder =1; // stringTKT =Qwc.ticket (MemberID, order); Ticket T= jsonconvert.deserializeobject<ticket>(TKT); stringURL =Xxxxxxxxxxxxxxxxxxxxxx;//t.url; To generate the URL address for the QR code//Verify URL if(URL.) Length = =0) { //UTILS.SHOWMSG2 (This, "Please enter the URL"); return; } //generate two-dimensional codeQrcodeencoder qrentity =NewQrcodeencoder (); Qrentity.qrcodeencodemode= Qrcodeencoder.encode_mode. BYTE;//Two-dimensional code encoding methodQrentity.qrcodescale =Ten;//the width of each small squareQrentity.qrcodeversion =5;//Two-dimensional code version numberQrentity.qrcodeerrorcorrect = qrcodeencoder.error_correction. M//Error correction code levelSystem.Drawing.Bitmap Srcimage; //dynamically adjust the QR code version number, upper limit 40, too long return blank picture, encoded character maximum byte length 2953 while(true) { Try{srcimage=qrentity.encode (URL, System.Text.Encoding.UTF8); Break; } Catch(IndexOutOfRangeException ex) {if(Qrentity.qrcodeversion < +) {qrentity.qrcodeversion++; } Else{srcimage=NewBitmap ( -, -); Break; }}} System.Drawing.Image img= System.Drawing.Image.FromFile (Server.MapPath ("~/images/favicon.jpg")); if(img! =NULL) { //System.IO.Stream picstream = img1. InputStream; //System.Drawing.Image img = System.Drawing.Image.FromStream (picstream); if(IMG. Width > -|| Img. Height > -) {img. Dispose (); //(This, "Upload logo image error, logo image width can not exceed 250px, and height can not exceed 250px! "); return; Img. Dispose (); } //draw the logo to a two-dimensional codeBitmap Blogo = img asBitmap;//Get logo Image ObjectBlogo =NewBitmap (Blogo, -, -);//change the size of the picture here we set it to intY =Srcimage. Height; intX =Srcimage. Width; Point Point=NewPoint (X/2- theY2- the);//logo image is drawn to the QR code, here will be a simple calculation of the logo coordinatesGraphics g = graphics.fromimage (srcimage);//Create a canvasG.drawimage (Blogo, point);//draw the logo image to the QR code image//imgqr.imageurl = srcimage; } stringTempdire = Server.MapPath ("~/IMGES/QT"); if(!directory.exists (Tempdire)) {directory.createdirectory (tempdire);} stringImgpath ="~/imges/qt/"+ DateTime.Now.ToString ("yyyy_mm_dd_hh_ss_mm") +". bmp"; Srcimage. Save (Server.MapPath (Imgpath));
2. Upload the type upload using FileUpload must refer to the ThoughtWorks.QRCode.dll
//Verify URL stringURL = This. TxtURL.Text.Trim (); if(URL.) Length = =0) {UTILS.SHOWMSG2 ( This,"Please enter the URL"); return; } //generate two-dimensional codeQrcodeencoder qrentity =NewQrcodeencoder (); Qrentity.qrcodeencodemode= Qrcodeencoder.encode_mode. BYTE;//Two-dimensional code encoding methodQrentity.qrcodescale =Ten;//the width of each small squareQrentity.qrcodeversion =5;//Two-dimensional code version numberQrentity.qrcodeerrorcorrect = qrcodeencoder.error_correction. M//Error correction code levelSystem.Drawing.Bitmap Srcimage; //dynamically adjust the QR code version number, upper limit 40, too long return blank picture, encoded character maximum byte length 2953 while(true) { Try{srcimage=qrentity.encode (URL, System.Text.Encoding.UTF8); Break; } Catch(IndexOutOfRangeException ex) {if(Qrentity.qrcodeversion < +) {qrentity.qrcodeversion++; } Else{srcimage=NewBitmap ( -, -); Break; } } } //Verify logoHttppostedfile logo =Filelogo.postedfile; if(Logo. ContentLength >0) { if(!utils.isimage (logo). InputStream)) {UTILS.SHOWMSG2 ( This,"Picture Format Error"); return; } System.IO.Stream Picstream=logo. InputStream; System.Drawing.Image img=System.Drawing.Image.FromStream (Picstream); if(IMG. Width > -|| Img. Height > -) {img. Dispose (); UTILS.SHOWMSG2 ( This,"Upload logo image error, logo image width can not exceed 250px, and height can not exceed 250px! "); return; Img. Dispose (); } //draw the logo to a two-dimensional codeBitmap Blogo = img asBitmap;//Get logo Image ObjectBlogo =NewBitmap (Blogo, -, -);//change the size of the picture here we set it to intY =Srcimage. Height; intX =Srcimage. Width; Point Point=NewPoint (X/2- theY2- the);//logo image is drawn to the QR code, here will be a simple calculation of the logo coordinatesGraphics g = graphics.fromimage (srcimage);//Create a canvasG.drawimage (Blogo, point);//draw the logo image to the QR code image//imgqr.imageurl = srcimage; } stringTempdire = Server.MapPath (".. /upload/supplier/"+ Currentsupplier.supplierid +"/qrbitmap/"); if(!directory.exists (Tempdire)) {directory.createdirectory (tempdire);} stringImgpath =".. /upload/supplier/"+ Currentsupplier.supplierid +"/qrbitmap/"+ Guid.NewGuid (). ToString () +". bmp"; Srcimage. Save (Server.MapPath (Imgpath));
Generate QR Code function