DataFlex Requires Chilkat v11.7.0+
DataFlex
QR Code Quiet Zone, Padding and Rotation
See more QR Code Examples
Demonstrates the space around a QR code and its rotation. The quiet zone is the blank margin a reader needs around the symbol. It is measured in modules, the QR standard requires 4, and QrCode will make it larger but not smaller. Padding is extra space outside the quiet zone, measured in the render units (pixels by default). Rotation turns the whole image by 90, 180 or 270 degrees. A QR code reads the same at any rotation.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Variant vJson
Handle hoJson
Handle hoFmt
Variant vJsonOut
Handle hoJsonOut
String sTemp1
Integer iTemp1
Integer iTemp2
Integer iTemp3
Integer iTemp4
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "payload.text" "https://www.chilkatsoft.com/" To iSuccess
Get ComUpdateInt Of hoJson "render.moduleSize" 6 To iSuccess
// A quiet zone of 6 modules on every side instead of the standard 4.
Get ComUpdateInt Of hoJson "render.quietZone.left" 6 To iSuccess
Get ComUpdateInt Of hoJson "render.quietZone.top" 6 To iSuccess
Get ComUpdateInt Of hoJson "render.quietZone.right" 6 To iSuccess
Get ComUpdateInt Of hoJson "render.quietZone.bottom" 6 To iSuccess
// 10 more pixels of background around that.
Get ComUpdateInt Of hoJson "render.padding" 10 To iSuccess
// Turn the image a quarter turn clockwise.
Get ComUpdateInt Of hoJson "render.rotation" 90 To iSuccess
Get ComUpdateString Of hoJson "output.path" "qa_output/qr_margins.png" To iSuccess
Get ComUpdateBool Of hoJson "output.overwrite" True To iSuccess
Get ComUpdateString Of hoJson "output.return" "none" To iSuccess
Get Create (RefClass(cComChilkatFormats)) To hoFmt
If (Not(IsComObjectCreated(hoFmt))) Begin
Send CreateComObject of hoFmt
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOut
If (Not(IsComObjectCreated(hoJsonOut))) Begin
Send CreateComObject of hoJsonOut
End
Get pvComObject of hoJson to vJson
Get pvComObject of hoJsonOut to vJsonOut
Get ComQrCode Of hoFmt "generate" vJson vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFmt To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComIntOf Of hoJsonOut "measurements[0].pitch" To iTemp1
Showln "module: " iTemp1 " pixels"
Get ComIntOf Of hoJsonOut "measurements[0].symbolWidth" To iTemp1
Get ComIntOf Of hoJsonOut "measurements[0].symbolHeight" To iTemp2
Get ComIntOf Of hoJsonOut "measurements[0].symbolX" To iTemp3
Get ComIntOf Of hoJsonOut "measurements[0].symbolY" To iTemp4
Showln "symbol: " iTemp1 " x " iTemp2 " pixels at (" iTemp3 "," iTemp4 ")"
Get ComIntOf Of hoJsonOut "measurements[0].quietZonePx.left" To iTemp1
Showln "quiet zone: " iTemp1 " pixels"
Get ComIntOf Of hoJsonOut "measurements[0].paddingPx" To iTemp1
Showln "padding: " iTemp1 " pixels"
Get ComIntOf Of hoJsonOut "measurements[0].rotation" To iTemp1
Showln "rotation: " iTemp1
Get ComIntOf Of hoJsonOut "measurements[0].canvasWidth" To iTemp1
Get ComIntOf Of hoJsonOut "measurements[0].canvasHeight" To iTemp2
Showln "image: " iTemp1 " x " iTemp2 " pixels"
// The image, enlarged, with the quiet zone and the padding tinted here to show where they are.
// In the image itself both are plain white. A QR code has no finder pattern (the large squares)
// in its bottom right corner. After the quarter turn that corner is at the bottom left:
//
// Sample output:
// module: 6 pixels
// symbol: 174 x 174 pixels at (46,46)
// quiet zone: 36 pixels
// padding: 10 pixels
// rotation: 90
// image: 266 x 266 pixels
End_Procedure