DataFlex Requires Chilkat v11.7.0+
DataFlex
Measure a QR Code without Rendering It
See more QR Code Examples
Demonstrates the measure operation, which does everything generate does except draw the image. It reports the version chosen and the exact size the image would have, which is useful for laying out a page or a label before any image is made. Unlike generate, a code that does not fit the limits is not a failure for measure: the call succeeds, fits is false, and reasons[] says why.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Variant vJson
Handle hoJson
Handle hoFmt
Variant vJsonOut
Handle hoJsonOut
String sTemp1
String sTemp2
Integer iTemp1
Integer iTemp2
Boolean bTemp1
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/barcode_overview.asp" To iSuccess
Get ComUpdateInt Of hoJson "render.moduleSize" 8 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 "measure" vJson vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFmt To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComBoolOf Of hoJsonOut "fits" To bTemp1
Showln "fits: " bTemp1
Get ComIntOf Of hoJsonOut "symbols[0].selectedEncoding.version" To iTemp1
Showln "QR version: " iTemp1
Get ComIntOf Of hoJsonOut "measurements[0].canvasWidth" To iTemp1
Get ComIntOf Of hoJsonOut "measurements[0].canvasHeight" To iTemp2
Showln "image would be: " iTemp1 " x " iTemp2 " pixels"
Get ComIntOf Of hoJsonOut "measurements[0].symbolWidth" To iTemp1
Get ComIntOf Of hoJsonOut "measurements[0].symbolX" To iTemp2
Showln "symbol: " iTemp1 " pixels wide at x = " iTemp2
// Would it fit in a space 200 pixels wide?
Get ComUpdateInt Of hoJson "render.maxWidth" 200 To iSuccess
Get pvComObject of hoJson to vJson
Get pvComObject of hoJsonOut to vJsonOut
Get ComQrCode Of hoFmt "measure" vJson vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFmt To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComBoolOf Of hoJsonOut "fits" To bTemp1
Showln "within 200 pixels, fits: " bTemp1
Get ComBoolOf Of hoJsonOut "fits" To bTemp1
If (bTemp1 = False) Begin
Get ComStringOf Of hoJsonOut "reasons[0].code" To sTemp1
Get ComStringOf Of hoJsonOut "reasons[0].message" To sTemp2
Showln "reason: " sTemp1 " (" sTemp2 ")"
End
// What measure reported, drawn as a diagram. The measure operation itself makes no image:
//
// Sample output:
// fits: True
// QR version: 4
// image would be: 328 x 328 pixels
// symbol: 264 pixels wide at x = 32
// within 200 pixels, fits: False
// reason: noFit (exceedsMaxWidth)
End_Procedure