Visual FoxPro Requires Chilkat v11.7.0+
Visual FoxPro
Get the Modules of a QR Code (Bit Matrix)
See more QR Code Examples
Demonstrates getting the QR code itself, as a grid of dark and light modules, to draw with something other than the built-in PNG and SVG output: on a canvas, in a PDF, on a display, or with a label printer language. With output.includeModuleData the response has symbols[0].moduleData, a bit matrix with one bit per module, each row starting on a new byte, most significant bit first, 1 for dark. The quiet zone is not part of the matrix. The example prints the symbol using two characters per module.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loJson
LOCAL loFmt
LOCAL loJsonOut
LOCAL lnWidth
LOCAL lnHeight
LOCAL lnRowBytes
LOCAL loBd
LOCAL loSbRow
LOCAL lnRow
LOCAL lnCol
LOCAL b
LOCAL lnMask
lnSuccess = 0
* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("payload.text","CHILKAT")
loJson.UpdateBool("output.includeModuleData",1)
loFmt = CreateObject('Chilkat.Formats')
loJsonOut = CreateObject('Chilkat.JsonObject')
lnSuccess = loFmt.QrCode("generate",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
? loFmt.LastErrorText
RELEASE loJson
RELEASE loFmt
RELEASE loJsonOut
CANCEL
ENDIF
lnWidth = loJsonOut.IntOf("symbols[0].moduleData.width")
lnHeight = loJsonOut.IntOf("symbols[0].moduleData.height")
lnRowBytes = loJsonOut.IntOf("symbols[0].moduleData.rowBytes")
? "kind: " + loJsonOut.StringOf("symbols[0].moduleData.kind")
? "modules: " + STR(lnWidth) + " x " + STR(lnHeight) + ", " + STR(lnRowBytes) + " bytes per row"
* The matrix is height rows of rowBytes bytes.
loBd = CreateObject('Chilkat.BinData')
lnSuccess = loBd.AppendEncoded(loJsonOut.StringOf("symbols[0].moduleData.bytesBase64"),"base64")
IF (lnSuccess = 0) THEN
? loBd.LastErrorText
RELEASE loJson
RELEASE loFmt
RELEASE loJsonOut
RELEASE loBd
CANCEL
ENDIF
loSbRow = CreateObject('Chilkat.StringBuilder')
lnMask = 128
FOR lnRow = 0 TO lnHeight - 1
loSbRow.Clear()
FOR lnCol = 0 TO lnWidth - 1
* The module at (col,row) is a bit of the byte at (row * rowBytes) + (col / 8).
* The leftmost module of each byte is its most significant bit.
IF ((lnCol % 8) = 0) THEN
lnMask = 128
ENDIF
b = loBd.GetByte((lnRow * lnRowBytes) + (lnCol / 8))
IF (((b / lnMask) % 2) = 1) THEN
loSbRow.Append("##")
ELSE
loSbRow.Append(" ")
ENDIF
lnMask = lnMask / 2
NEXT
? loSbRow.GetAsString()
NEXT
* The same symbol as the PNG that the call also returned:
*
* Sample output:
* kind: bitMatrix
* modules: 21 x 21, 3 bytes per row
* ############## ##############
* ## ## #### ## ##
* ## ###### ## ## #### ## ###### ##
* ## ###### ## ## ## ###### ##
* ## ###### ## ## ## ## ## ###### ##
* ## ## #### ## ## ##
* ############## ## ## ## ##############
* ####
* ## ########## #### ##########
* #### ## ######## ######
* #### ######## #### ## #### ####
* ## ## ############ #### ##
* ###### #### ###### ## ## ##
* ## ## ## ## ## ##
* ############## ## ## ## ##
* ## ## ## ## ###### ####
* ## ###### ## #### ## ## ##
* ## ###### ## ## ############ ##
* ## ###### ## ## ## #### ##
* ## ## ## ######## ##
* ############## ## ## ######
RELEASE loJson
RELEASE loFmt
RELEASE loJsonOut
RELEASE loBd
RELEASE loSbRow