Unicode C Requires Chilkat v11.7.0+
Unicode C
QR Code Error Correction Levels
See more QR Code Examples
Demonstrates the four QR error-correction levels. L, M, Q and H allow a reader to recover the data when about 7%, 15%, 25% and 30% of the symbol is damaged or covered. More error correction leaves less room for data, so the same text needs a larger symbol at a higher level. The default is M. The example also shows boostErrorCorrection, which raises the level for free when the chosen version has room to spare.Chilkat Unicode C Downloads
#include <C_CkFormatsW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkJsonArrayW.h>
void ChilkatSample(void)
{
BOOL success;
HCkFormatsW fmt;
HCkJsonObjectW json;
HCkJsonObjectW jsonOut;
HCkJsonArrayW levels;
int i;
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();
json = CkJsonObjectW_Create();
jsonOut = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"payload.text",L"https://www.chilkatsoft.com/barcode_overview.asp");
// Encode the same text at each level.
levels = CkJsonArrayW_Create();
CkJsonArrayW_Load(levels,L"[\"L\",\"M\",\"Q\",\"H\"]");
for (i = 0; i <= 3; i++) {
CkJsonObjectW_UpdateString(json,L"encoding.qr.errorCorrection",CkJsonArrayW_stringAt(levels,i));
success = CkFormatsW_QrCode(fmt,L"generate",json,jsonOut);
if (success == FALSE) {
wprintf(L"%s\n",CkFormatsW_lastErrorText(fmt));
CkFormatsW_Dispose(fmt);
CkJsonObjectW_Dispose(json);
CkJsonObjectW_Dispose(jsonOut);
CkJsonArrayW_Dispose(levels);
return;
}
wprintf(L"level %s: version %d, %d modules wide\n",CkJsonArrayW_stringAt(levels,i),CkJsonObjectW_IntOf(jsonOut,L"symbols[0].selectedEncoding.version"),CkJsonObjectW_IntOf(jsonOut,L"symbols[0].dimensions.modulesWide"));
}
// The four symbols. They hold the same text, and the higher the level, the larger the symbol:
//
// A symbol often has room left over. boostErrorCorrection uses it: the level is raised
// as far as the same version allows, so the symbol is no larger but is more robust.
json2 = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json2,L"payload.text",L"https://chilkatsoft.com");
CkJsonObjectW_UpdateString(json2,L"encoding.qr.errorCorrection",L"L");
success = CkFormatsW_QrCode(fmt,L"generate",json2,jsonOut);
if (success == FALSE) {
wprintf(L"%s\n",CkFormatsW_lastErrorText(fmt));
CkFormatsW_Dispose(fmt);
CkJsonObjectW_Dispose(json);
CkJsonObjectW_Dispose(jsonOut);
CkJsonArrayW_Dispose(levels);
CkJsonObjectW_Dispose(json2);
return;
}
wprintf(L"level L requested: version %d, level %s\n",CkJsonObjectW_IntOf(jsonOut,L"symbols[0].selectedEncoding.version"),CkJsonObjectW_stringOf(jsonOut,L"symbols[0].selectedEncoding.errorCorrection"));
CkJsonObjectW_UpdateBool(json2,L"encoding.qr.boostErrorCorrection",TRUE);
success = CkFormatsW_QrCode(fmt,L"generate",json2,jsonOut);
if (success == FALSE) {
wprintf(L"%s\n",CkFormatsW_lastErrorText(fmt));
CkFormatsW_Dispose(fmt);
CkJsonObjectW_Dispose(json);
CkJsonObjectW_Dispose(jsonOut);
CkJsonArrayW_Dispose(levels);
CkJsonObjectW_Dispose(json2);
return;
}
wprintf(L"level L with boost: version %d, level %s\n",CkJsonObjectW_IntOf(jsonOut,L"symbols[0].selectedEncoding.version"),CkJsonObjectW_stringOf(jsonOut,L"symbols[0].selectedEncoding.errorCorrection"));
// Level L, and level M reached by the boost. The two symbols are the same size:
//
// Sample output:
// level L: version 3, 29 modules wide
// level M: version 4, 33 modules wide
// level Q: version 5, 37 modules wide
// level H: version 6, 41 modules wide
// level L requested: version 2, level L
// level L with boost: version 2, level M
CkFormatsW_Dispose(fmt);
CkJsonObjectW_Dispose(json);
CkJsonObjectW_Dispose(jsonOut);
CkJsonArrayW_Dispose(levels);
CkJsonObjectW_Dispose(json2);
}