Search code examples
asp.netvbavb.netqr-codezxing

QRcode using ZXing (Issue with Error Correction)


Here is the code for ASP.net, this script run on a IIS (QR_Code.aspx)

OS: Windows 10 PRO

<%@ Page language="vb" debug=true %>
<%@ Import NameSpace = "Zxing.Interop.Encoding.BarcodeWriter" %>
<%@ Import NameSpace = "System.IO" %>
<%@ Import NameSpace = "System.Drawing" %>

'-----------------------------------------------'
'QR-Code
'-----------------------------------------------'
Dim ZX As New ZXing.BarcodeWriter
Dim bmp As Bitmap

Zx.Format = ZXing.BarcodeFormat.QR_CODE
Zx.Options.Height = 250
Zx.Options.Width = 250
Zx.Options.Margin = 0.9
Zx.Options.PureBarcode = True
Zx.Format = 2048

bmp = Zx.Write("Test_1234")
bmp.Save("c:\inetpub\wwwroot\tester\qrcode.png", Imaging.ImageFormat.Png)
'-----------------------------------------------'

The above code is working just fine but my problem is that I'm unable to find any correct reference for the "Error correction" for the above code.

I've tried the following code but no luck!

Zx.Options.ErrorCorrection = ErrorCorrectionLevel_H

or

Zx.ErrorCorrection = ErrorCorrectionLevel_H

or

ErrorCorrection = ErrorCorrectionLevel_H

Keep getting this error message from the browser

Compiler Error Message: BC30456: 'ErrorCorrection' is not a member of 'ZXing.Common.EncodingOptions'.

For your information:

Filename: zxing.dll
File Description: Zxing.net for 3.5
File Version: 0.16.4.0
Sha256 Hash: e1ed37bb6d376a35a05169a6bad52c6d589eac3bc3d676fc4ed6336e84d59fea 

Thank your for your time to read this threat, please forgive me if i don't reply in correct format - I'm still new in here!


Solution

  • The following code snippet should work:

    <%@ Page language="vb" debug=true %>
    <%@ Import NameSpace = "System.Drawing" %>
    <%
    
    '-----------------------------------------------'
    'QR-Code
    '-----------------------------------------------'
    Dim ZX As New ZXing.BarcodeWriter
    Dim bmp As Bitmap
    Dim options as ZXing.QrCode.QrCodeEncodingOptions
    
    options = New ZXing.QrCode.QrCodeEncodingOptions
    options.ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.H
    options.Height = 250
    options.Width = 250
    options.Margin = 0.9
    options.PureBarcode = True
    
    Zx.Format = ZXing.BarcodeFormat.QR_CODE
    Zx.Options = options
    
    bmp = Zx.Write("Test_1234")
    bmp.Save("c:\inetpub\wwwroot\tester\qrcode.png", Imaging.ImageFormat.Png)
    '-----------------------------------------------'
    %>