Unicode C Requires Chilkat v11.7.0+
Unicode C
QR Code with a Text Caption
See more QR Code Examples
Demonstrates printing a line of text under a QR code, such as the order number or the address the code holds, so that a person can read it too. render.text turns the caption on and gives its value, which is printable ASCII and is drawn in a built-in font that needs no font files. The caption can go above or below the symbol, be aligned left, center or right, and be scaled.Chilkat Unicode C Downloads
#include <C_CkJsonObjectW.h>
#include <C_CkFormatsW.h>
void ChilkatSample(void)
{
BOOL success;
HCkJsonObjectW json;
HCkFormatsW fmt;
HCkJsonObjectW jsonOut;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"payload.text",L"https://www.chilkatsoft.com/order/12345");
CkJsonObjectW_UpdateInt(json,L"render.moduleSize",6);
// The caption. It need not be the same as the text in the QR code.
CkJsonObjectW_UpdateBool(json,L"render.text.enabled",TRUE);
CkJsonObjectW_UpdateString(json,L"render.text.value",L"ORDER 12345");
// position is "below" (the default) or "above". alignment is "center" (the default), "left" or "right".
CkJsonObjectW_UpdateString(json,L"render.text.position",L"below");
// Each dot of the caption's font is drawn this many pixels wide.
CkJsonObjectW_UpdateInt(json,L"render.text.scale",3);
CkJsonObjectW_UpdateString(json,L"output.path",L"qa_output/qr_caption.png");
CkJsonObjectW_UpdateBool(json,L"output.overwrite",TRUE);
CkJsonObjectW_UpdateString(json,L"output.return",L"none");
fmt = CkFormatsW_Create();
jsonOut = CkJsonObjectW_Create();
success = CkFormatsW_QrCode(fmt,L"generate",json,jsonOut);
if (success == FALSE) {
wprintf(L"%s\n",CkFormatsW_lastErrorText(fmt));
CkJsonObjectW_Dispose(json);
CkFormatsW_Dispose(fmt);
CkJsonObjectW_Dispose(jsonOut);
return;
}
wprintf(L"caption: %s\n",CkJsonObjectW_stringOf(jsonOut,L"measurements[0].text"));
wprintf(L"caption scale: %d\n",CkJsonObjectW_IntOf(jsonOut,L"measurements[0].textScale"));
wprintf(L"height added for the caption: %d pixels\n",CkJsonObjectW_IntOf(jsonOut,L"measurements[0].textBandPx"));
wprintf(L"image: %d x %d pixels\n",CkJsonObjectW_IntOf(jsonOut,L"measurements[0].canvasWidth"),CkJsonObjectW_IntOf(jsonOut,L"measurements[0].canvasHeight"));
// The image written to qa_output/qr_caption.png:
//
// Sample output:
// caption: ORDER 12345
// caption scale: 3
// height added for the caption: 21 pixels
// image: 222 x 243 pixels
CkJsonObjectW_Dispose(json);
CkFormatsW_Dispose(fmt);
CkJsonObjectW_Dispose(jsonOut);
}