Sample code for 30+ languages & platforms
AutoIt 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 AutoIt Downloads

AutoIt
Local $bSuccess = False

;  This example requires the Chilkat API to have been previously unlocked.
;  See Global Unlock Sample for sample code.

$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("payload.text","https://www.chilkatsoft.com/")
$oJson.UpdateInt("render.moduleSize",6)

$oFmt = ObjCreate("Chilkat.Formats")
$oJsonOut = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oFmt.QrCode("generate",$oJson,$oJsonOut)
If ($bSuccess = False) Then
    ConsoleWrite($oFmt.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("format: " & $oJsonOut.StringOf("outputs[0].format") & @CRLF)
ConsoleWrite("MIME type: " & $oJsonOut.StringOf("outputs[0].mimeType") & @CRLF)
ConsoleWrite("image: " & $oJsonOut.IntOf("outputs[0].width") & " x " & $oJsonOut.IntOf("outputs[0].height") & " pixels" & @CRLF)

;  outputs[0].base64 is the PNG file, base64 encoded.
$oBdPng = ObjCreate("Chilkat.BinData")
$bSuccess = $oBdPng.AppendEncoded($oJsonOut.StringOf("outputs[0].base64"),"base64")
If ($bSuccess = False) Then
    ConsoleWrite($oBdPng.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("PNG bytes: " & $oBdPng.NumBytes & @CRLF)

;  The BinData holds the image.  Here it is simply saved.
$bSuccess = $oBdPng.WriteFile("qa_output/qr_in_memory.png")
If ($bSuccess = False) Then
    ConsoleWrite($oBdPng.LastErrorText & @CRLF)
    Exit
EndIf

;  The PNG held in bdPng:

;  image

;  Sample output:

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