DataFlex Requires Chilkat v11.7.0+
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Variant vJson
Handle hoJson
Handle hoFmt
Variant vJsonOut
Handle hoJsonOut
Handle hoBdPng
String sTemp1
Integer iTemp1
Integer iTemp2
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/" To iSuccess
Get ComUpdateInt Of hoJson "render.moduleSize" 6 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 "generate" vJson vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFmt To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStringOf Of hoJsonOut "outputs[0].format" To sTemp1
Showln "format: " sTemp1
Get ComStringOf Of hoJsonOut "outputs[0].mimeType" To sTemp1
Showln "MIME type: " sTemp1
Get ComIntOf Of hoJsonOut "outputs[0].width" To iTemp1
Get ComIntOf Of hoJsonOut "outputs[0].height" To iTemp2
Showln "image: " iTemp1 " x " iTemp2 " pixels"
// outputs[0].base64 is the PNG file, base64 encoded.
Get Create (RefClass(cComChilkatBinData)) To hoBdPng
If (Not(IsComObjectCreated(hoBdPng))) Begin
Send CreateComObject of hoBdPng
End
Get ComStringOf Of hoJsonOut "outputs[0].base64" To sTemp1
Get ComAppendEncoded Of hoBdPng sTemp1 "base64" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoBdPng To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComNumBytes Of hoBdPng To iTemp1
Showln "PNG bytes: " iTemp1
// The BinData holds the image. Here it is simply saved.
Get ComWriteFile Of hoBdPng "qa_output/qr_in_memory.png" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoBdPng To sTemp1
Showln sTemp1
Procedure_Return
End
// The PNG held in bdPng:
//
// Sample output:
// format: png
// MIME type: image/png
// image: 222 x 222 pixels
// PNG bytes: 877
End_Procedure