Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.7.0+

Generate a QR Code PNG in Memory

See more QR Code Examples

Demonstrates getting a QR code image without writing a file. With no output options the result is a PNG returned as base64 in outputs[0].base64 of the response. The example decodes it into a BinData, which holds the bytes of the PNG to send in an HTTP response, store in a database, attach to an email, or save.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loJson
LOCAL loFmt
LOCAL loJsonOut
LOCAL loBdPng

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/")
loJson.UpdateInt("render.moduleSize",6)

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

? "format: " + loJsonOut.StringOf("outputs[0].format")
? "MIME type: " + loJsonOut.StringOf("outputs[0].mimeType")
? "image: " + STR(loJsonOut.IntOf("outputs[0].width")) + " x " + STR(loJsonOut.IntOf("outputs[0].height")) + " pixels"

*  outputs[0].base64 is the PNG file, base64 encoded.
loBdPng = CreateObject('Chilkat.BinData')
lnSuccess = loBdPng.AppendEncoded(loJsonOut.StringOf("outputs[0].base64"),"base64")
IF (lnSuccess = 0) THEN
    ? loBdPng.LastErrorText
    RELEASE loJson
    RELEASE loFmt
    RELEASE loJsonOut
    RELEASE loBdPng
    CANCEL
ENDIF

? "PNG bytes: " + STR(loBdPng.NumBytes)

*  The BinData holds the image.  Here it is simply saved.
lnSuccess = loBdPng.WriteFile("qa_output/qr_in_memory.png")
IF (lnSuccess = 0) THEN
    ? loBdPng.LastErrorText
    RELEASE loJson
    RELEASE loFmt
    RELEASE loJsonOut
    RELEASE loBdPng
    CANCEL
ENDIF

*  The PNG held in bdPng:

*  image

*  Sample output:

*  format: png
*  MIME type: image/png
*  image: 222 x 222 pixels
*  PNG bytes: 877

RELEASE loJson
RELEASE loFmt
RELEASE loJsonOut
RELEASE loBdPng