PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Json
oleobject loo_Fmt
oleobject loo_JsonOut
long li_Width
long li_Height
long li_RowBytes
oleobject loo_Bd
oleobject loo_SbRow
long li_Row
long li_Col
long b
long li_Mask
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
if li_rc < 0 then
destroy loo_Json
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Json.UpdateString("payload.text","CHILKAT")
loo_Json.UpdateBool("output.includeModuleData",1)
loo_Fmt = create oleobject
li_rc = loo_Fmt.ConnectToNewObject("Chilkat.Formats")
loo_JsonOut = create oleobject
li_rc = loo_JsonOut.ConnectToNewObject("Chilkat.JsonObject")
li_Success = loo_Fmt.QrCode("generate",loo_Json,loo_JsonOut)
if li_Success = 0 then
Write-Debug loo_Fmt.LastErrorText
destroy loo_Json
destroy loo_Fmt
destroy loo_JsonOut
return
end if
li_Width = loo_JsonOut.IntOf("symbols[0].moduleData.width")
li_Height = loo_JsonOut.IntOf("symbols[0].moduleData.height")
li_RowBytes = loo_JsonOut.IntOf("symbols[0].moduleData.rowBytes")
Write-Debug "kind: " + loo_JsonOut.StringOf("symbols[0].moduleData.kind")
Write-Debug "modules: " + string(li_Width) + " x " + string(li_Height) + ", " + string(li_RowBytes) + " bytes per row"
// The matrix is height rows of rowBytes bytes.
loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")
li_Success = loo_Bd.AppendEncoded(loo_JsonOut.StringOf("symbols[0].moduleData.bytesBase64"),"base64")
if li_Success = 0 then
Write-Debug loo_Bd.LastErrorText
destroy loo_Json
destroy loo_Fmt
destroy loo_JsonOut
destroy loo_Bd
return
end if
loo_SbRow = create oleobject
li_rc = loo_SbRow.ConnectToNewObject("Chilkat.StringBuilder")
li_Mask = 128
for row = 0 to li_Height - 1
loo_SbRow.Clear()
for col = 0 to li_Width - 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 (li_Col % 8) = 0 then
li_Mask = 128
end if
b = loo_Bd.GetByte((li_Row * li_RowBytes) + (li_Col / 8))
if ((b / li_Mask) % 2) = 1 then
loo_SbRow.Append("##")
else
loo_SbRow.Append(" ")
end if
li_Mask = li_Mask / 2
next
Write-Debug loo_SbRow.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
// ############## ##############
// ## ## #### ## ##
// ## ###### ## ## #### ## ###### ##
// ## ###### ## ## ## ###### ##
// ## ###### ## ## ## ## ## ###### ##
// ## ## #### ## ## ##
// ############## ## ## ## ##############
// ####
// ## ########## #### ##########
// #### ## ######## ######
// #### ######## #### ## #### ####
// ## ## ############ #### ##
// ###### #### ###### ## ## ##
// ## ## ## ## ## ##
// ############## ## ## ## ##
// ## ## ## ## ###### ####
// ## ###### ## #### ## ## ##
// ## ###### ## ## ############ ##
// ## ###### ## ## ## #### ##
// ## ## ## ######## ##
// ############## ## ## ######
destroy loo_Json
destroy loo_Fmt
destroy loo_JsonOut
destroy loo_Bd
destroy loo_SbRow