Visual FoxPro Requires Chilkat v11.7.0+
Visual FoxPro
Fit a QR Code within a Maximum Size
See more QR Code Examples
Demonstrates limiting the size of the image. render.maxWidth and render.maxHeight are the largest image allowed. With render.sizing set to shrinkToFit, QrCode starts from the module size asked for and reduces it, a whole pixel at a time, until the image fits, but never below render.minModuleSize. If it cannot fit, the call fails with noFit rather than returning a code too small to scan.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loJson
LOCAL loFmt
LOCAL loJsonOut
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","https://www.chilkatsoft.com/barcode_overview.asp")
* Ask for 10-pixel modules, but accept anything down to 3 pixels to stay within 300 x 300.
loJson.UpdateInt("render.moduleSize",10)
loJson.UpdateString("render.sizing","shrinkToFit")
loJson.UpdateInt("render.minModuleSize",3)
loJson.UpdateInt("render.maxWidth",300)
loJson.UpdateInt("render.maxHeight",300)
loJson.UpdateString("output.path","qa_output/qr_fit_300.png")
loJson.UpdateBool("output.overwrite",1)
loJson.UpdateString("output.return","none")
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
? "module asked for: " + loJsonOut.StringOf("measurements[0].requestedPitch") + " pixels"
? "module used: " + STR(loJsonOut.IntOf("measurements[0].pitch")) + " pixels"
? "image: " + STR(loJsonOut.IntOf("measurements[0].canvasWidth")) + " x " + STR(loJsonOut.IntOf("measurements[0].canvasHeight")) + " pixels"
* The image written to qa_output/qr_fit_300.png:
*
* The same code cannot fit in 100 x 100 with modules of at least 3 pixels.
loJson.UpdateInt("render.maxWidth",100)
loJson.UpdateInt("render.maxHeight",100)
lnSuccess = loFmt.QrCode("generate",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
? "100 x 100: " + loJsonOut.StringOf("errors[0].code") + " (" + loJsonOut.StringOf("errors[0].message") + ")"
ENDIF
* Sample output:
* module asked for: 10 pixels
* module used: 7 pixels
* image: 287 x 287 pixels
* 100 x 100: noFit (the symbol does not fit the render constraints: minModuleSize)
RELEASE loJson
RELEASE loFmt
RELEASE loJsonOut