Unicode C Requires Chilkat v11.7.0+
Unicode C
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 Unicode C Downloads
#include <C_CkFormatsW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkFormatsW fmt;
HCkJsonObjectW jsonOut;
HCkJsonObjectW json;
HCkJsonObjectW json2;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
fmt = CkFormatsW_Create();
jsonOut = CkJsonObjectW_Create();
// Dark blue modules on a pale yellow background.
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"payload.text",L"https://www.chilkatsoft.com/");
CkJsonObjectW_UpdateInt(json,L"render.moduleSize",6);
CkJsonObjectW_UpdateString(json,L"render.foreground",L"#1B3A6B");
CkJsonObjectW_UpdateString(json,L"render.background",L"#FFF8DC");
CkJsonObjectW_UpdateString(json,L"output.path",L"qa_output/qr_blue.png");
CkJsonObjectW_UpdateBool(json,L"output.overwrite",TRUE);
CkJsonObjectW_UpdateString(json,L"output.return",L"none");
success = CkFormatsW_QrCode(fmt,L"generate",json,jsonOut);
if (success == FALSE) {
wprintf(L"%s\n",CkFormatsW_lastErrorText(fmt));
CkFormatsW_Dispose(fmt);
CkJsonObjectW_Dispose(jsonOut);
CkJsonObjectW_Dispose(json);
return;
}
wprintf(L"colored: %s, %d bytes\n",CkJsonObjectW_stringOf(jsonOut,L"outputs[0].path"),CkJsonObjectW_IntOf(jsonOut,L"outputs[0].byteCount"));
// The image written to qa_output/qr_blue.png:
//
// The same modules on a fully transparent background.
json2 = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json2,L"payload.text",L"https://www.chilkatsoft.com/");
CkJsonObjectW_UpdateInt(json2,L"render.moduleSize",6);
CkJsonObjectW_UpdateString(json2,L"render.foreground",L"#1B3A6B");
CkJsonObjectW_UpdateString(json2,L"render.background.color",L"#FFFFFF");
CkJsonObjectW_UpdateNumber(json2,L"render.background.opacity",L"0");
CkJsonObjectW_UpdateString(json2,L"output.path",L"qa_output/qr_transparent.png");
CkJsonObjectW_UpdateBool(json2,L"output.overwrite",TRUE);
CkJsonObjectW_UpdateString(json2,L"output.return",L"none");
success = CkFormatsW_QrCode(fmt,L"generate",json2,jsonOut);
if (success == FALSE) {
wprintf(L"%s\n",CkFormatsW_lastErrorText(fmt));
CkFormatsW_Dispose(fmt);
CkJsonObjectW_Dispose(jsonOut);
CkJsonObjectW_Dispose(json);
CkJsonObjectW_Dispose(json2);
return;
}
wprintf(L"transparent: %s, %d bytes\n",CkJsonObjectW_stringOf(jsonOut,L"outputs[0].path"),CkJsonObjectW_IntOf(jsonOut,L"outputs[0].byteCount"));
// 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
CkFormatsW_Dispose(fmt);
CkJsonObjectW_Dispose(jsonOut);
CkJsonObjectW_Dispose(json);
CkJsonObjectW_Dispose(json2);
}