DataFlex Requires Chilkat v11.7.0+
DataFlex
QR Code Colors and Transparent Background
See more QR Code Examples
Demonstrates colored QR codes. render.foreground is the color of the dark modules and render.background the color behind them, each as #RRGGBB. Either can instead be an object with a color and an opacity from 0 to 1, and a background opacity of 0 gives a PNG with a transparent background to place over a page or a design. Readers need contrast: keep the modules clearly darker than whatever ends up behind them.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoFmt
Variant vJsonOut
Handle hoJsonOut
Variant vJson
Handle hoJson
Variant vJson2
Handle hoJson2
String sTemp1
Integer iTemp1
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(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
// Dark blue modules on a pale yellow background.
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 ComUpdateString Of hoJson "render.foreground" "#1B3A6B" To iSuccess
Get ComUpdateString Of hoJson "render.background" "#FFF8DC" To iSuccess
Get ComUpdateString Of hoJson "output.path" "qa_output/qr_blue.png" To iSuccess
Get ComUpdateBool Of hoJson "output.overwrite" True To iSuccess
Get ComUpdateString Of hoJson "output.return" "none" To iSuccess
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].path" To sTemp1
Get ComIntOf Of hoJsonOut "outputs[0].byteCount" To iTemp1
Showln "colored: " sTemp1 ", " iTemp1 " bytes"
// The image written to qa_output/qr_blue.png:
//
// The same modules on a fully transparent background.
Get Create (RefClass(cComChilkatJsonObject)) To hoJson2
If (Not(IsComObjectCreated(hoJson2))) Begin
Send CreateComObject of hoJson2
End
Get ComUpdateString Of hoJson2 "payload.text" "https://www.chilkatsoft.com/" To iSuccess
Get ComUpdateInt Of hoJson2 "render.moduleSize" 6 To iSuccess
Get ComUpdateString Of hoJson2 "render.foreground" "#1B3A6B" To iSuccess
Get ComUpdateString Of hoJson2 "render.background.color" "#FFFFFF" To iSuccess
Get ComUpdateNumber Of hoJson2 "render.background.opacity" "0" To iSuccess
Get ComUpdateString Of hoJson2 "output.path" "qa_output/qr_transparent.png" To iSuccess
Get ComUpdateBool Of hoJson2 "output.overwrite" True To iSuccess
Get ComUpdateString Of hoJson2 "output.return" "none" To iSuccess
Get pvComObject of hoJson2 to vJson2
Get pvComObject of hoJsonOut to vJsonOut
Get ComQrCode Of hoFmt "generate" vJson2 vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFmt To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStringOf Of hoJsonOut "outputs[0].path" To sTemp1
Get ComIntOf Of hoJsonOut "outputs[0].byteCount" To iTemp1
Showln "transparent: " sTemp1 ", " iTemp1 " bytes"
// qa_output/qr_transparent.png, placed here over a checkerboard and over a colored page
// to show that whatever is behind the image shows through:
//
// Sample output:
// colored: qa_output/qr_blue.png, 1345 bytes
// transparent: qa_output/qr_transparent.png, 1377 bytes
End_Procedure