"VB.net" uses zxing.net to generate QR codes (custom logos supported)

Source: Internet
Author: User

ZXing. NET Project home Page
https://zxingnet.codeplex.com/

Code basically copied from the following two articles XD
Http://www.cnblogs.com/tianma3798/p/5426869.html
Http://www.cnblogs.com/tianma3798/p/5426880.html


Optimized for parameters, more practical and easier

Shared FunctionMAKEQR (ByValQrtext as String,Optional ByValWidth as Integer= -,Optional ByValHeight as Integer= -,Optional ByValMargin as Integer=1) asBitmapDimWriter as Newzxing.barcodewriter Writer. Format=ZXing.BarcodeFormat.QR_CODEDimOpt as NewZXing.QrCode.QrCodeEncodingOptions opt. Disableeci=True 'set to True to adjust the encodingOpt. CharacterSet ="UTF-8" 'text encoding, recommended set to UTF-8Opt. width = width'widthOpt. Height = height'HeightOpt. margin = margin'margins, seemingly not pixel format, so it is not appropriate to set too largewriter. Options=optReturnwriter. Write (Qrtext)End FunctionShared FunctionMAKEQR (ByValQrtext as String,ByValLogo asBitmap,Optional ByValWidth as Integer= -,Optional ByValHeight as Integer= -,Optional ByValMargin as Integer=1) asBitmapIfLogo is  Nothing  Then        ReturnMAKEQR (qrtext, width, height, margin)End If    DimWriter as NewZxing.multiformatwriterDimHint as NewDictionary ( ofZxing.encodehinttype,Object) () hint. ADD (ZXing.EncodeHintType.CHARACTER_SET,"UTF-8") hint. ADD (ZXing.EncodeHintType.MARGIN, MARGIN) hint. ADD (ZXing.EncodeHintType.ERROR_CORRECTION, zxing.qrcode.internal.errorcorrectionlevel.h)'generate two-dimensional code    DimBm asZXing.Common.BitMatrix =Writer.encode (Qrtext, ZXing.BarcodeFormat.QR_CODE, width, height, hint)DimBarcodewriter =NewZxing.barcodewriter ()DimBmp asBitmap =Barcodewriter.write (BM)'get the actual size of the QR code (remove the actual size after the two-dimensional code is blank)    DimRectangle as Integer() =Bm.getenclosingrectangle ()'calculate the size and position of the inserted picture    DimMiddlew as Integer= Math.min ((Rectangle (2) /3.5), logo. Width)DimMiddleh as Integer= Math.min ((Rectangle (3) /3.5), logo. Height)DimMiddlel as Integer= (BMP. Width-middlew)/2    DimMiddlet as Integer= (BMP. Height-middleh)/2    'convert img to BMP format, otherwise the graphics object cannot be created later    DimBmpimg as NewBitmap (BMP. Width, BMP. Height, Imaging.PixelFormat.Format32bppArgb)UsingG asGraphics =graphics.fromimage (bmpimg) G.interpolationmode=Drawing2D.InterpolationMode.HighQualityBicubic G.smoothingmode=Drawing2D.SmoothingMode.HighQuality g.compositingquality=Drawing2D.CompositingQuality.HighQuality g.drawimage (BMP,0,0)    End Using    'Insert the QR code into the picture    UsingMygraphic asGraphics =graphics.fromimage (bmpimg)'White backgroundMygraphic.fillrectangle (Brushes.white, Middlel, Middlet, Middlew, Middleh) mygraphic.drawimage (logo, MI Ddlel, Middlet, Middlew, Middleh)End Usingbmp. Dispose ()ReturnbmpimgEnd FunctionShared FunctionREADQR (ByValBmp asBITMAP) as String    DimReader as NewZxing.barcodereader Reader. Options.characterset="UTF-8"    DimRet asZxing.result =Reader. Decode (BMP)IfRet is  Nothing  Then        Return  Nothing    Else        Returnret. TextEnd IfEnd Function

"VB.net" uses zxing.net to generate QR codes (custom logos supported)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.