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

Embed a QR Code in HTML as a Data URI

See more QR Code Examples

Demonstrates putting a QR code directly into an HTML page or HTML email with no separate image file. The base64 PNG returned by QrCode becomes the src of an img tag as a data URI, which is the MIME type from outputs[0].mimeType followed by the base64 from outputs[0].base64.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loJson
LOCAL loFmt
LOCAL loJsonOut
LOCAL loSbHtml

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",5)

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

*  A data URI has the form  data:<MIME type>;base64,<base64 data>
loSbHtml = CreateObject('Chilkat.StringBuilder')
loSbHtml.Append('<html><body><p>Scan to visit chilkatsoft.com</p><img alt="QR code" width="')
loSbHtml.AppendInt(loJsonOut.IntOf("outputs[0].width"))
loSbHtml.Append('" height="')
loSbHtml.AppendInt(loJsonOut.IntOf("outputs[0].height"))
loSbHtml.Append('" src="data:')
loSbHtml.Append(loJsonOut.StringOf("outputs[0].mimeType"))
loSbHtml.Append(";base64,")
loSbHtml.Append(loJsonOut.StringOf("outputs[0].base64"))
loSbHtml.Append('"></body></html>')

lnSuccess = loSbHtml.WriteFile("qa_output/qr_page.html","utf-8",0)
IF (lnSuccess = 0) THEN
    ? loSbHtml.LastErrorText
    RELEASE loJson
    RELEASE loFmt
    RELEASE loJsonOut
    RELEASE loSbHtml
    CANCEL
ENDIF

? "image: " + STR(loJsonOut.IntOf("outputs[0].width")) + " x " + STR(loJsonOut.IntOf("outputs[0].height")) + " pixels"
? "HTML length: " + STR(loSbHtml.Length)

*  The page, as a browser shows it:

*  image

*  Sample output:

*  image: 185 x 185 pixels
*  HTML length: 1211

RELEASE loJson
RELEASE loFmt
RELEASE loJsonOut
RELEASE loSbHtml