Unicode C++ Requires Chilkat v11.7.0+
Unicode C++
Measure a QR Code without Rendering It
See more QR Code Examples
Demonstrates the measure operation, which does everything generate does except draw the image. It reports the version chosen and the exact size the image would have, which is useful for laying out a page or a label before any image is made. Unlike generate, a code that does not fit the limits is not a failure for measure: the call succeeds, fits is false, and reasons[] says why.Chilkat Unicode C++ Downloads
#include <CkJsonObjectW.h>
#include <CkFormatsW.h>
void ChilkatSample(void)
{
bool success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkJsonObjectW json;
json.UpdateString(L"payload.text",L"https://www.chilkatsoft.com/barcode_overview.asp");
json.UpdateInt(L"render.moduleSize",8);
CkFormatsW fmt;
CkJsonObjectW jsonOut;
success = fmt.QrCode(L"measure",json,jsonOut);
if (success == false) {
wprintf(L"%s\n",fmt.lastErrorText());
return;
}
wprintf(L"fits: %d\n",jsonOut.BoolOf(L"fits"));
wprintf(L"QR version: %d\n",jsonOut.IntOf(L"symbols[0].selectedEncoding.version"));
wprintf(L"image would be: %d x %d pixels\n",jsonOut.IntOf(L"measurements[0].canvasWidth"),jsonOut.IntOf(L"measurements[0].canvasHeight"));
wprintf(L"symbol: %d pixels wide at x = %d\n",jsonOut.IntOf(L"measurements[0].symbolWidth"),jsonOut.IntOf(L"measurements[0].symbolX"));
// Would it fit in a space 200 pixels wide?
json.UpdateInt(L"render.maxWidth",200);
success = fmt.QrCode(L"measure",json,jsonOut);
if (success == false) {
wprintf(L"%s\n",fmt.lastErrorText());
return;
}
wprintf(L"within 200 pixels, fits: %d\n",jsonOut.BoolOf(L"fits"));
if (jsonOut.BoolOf(L"fits") == false) {
wprintf(L"reason: %s (%s)\n",jsonOut.stringOf(L"reasons[0].code"),jsonOut.stringOf(L"reasons[0].message"));
}
// What measure reported, drawn as a diagram. The measure operation itself makes no image:
//
// Sample output:
// fits: True
// QR version: 4
// image would be: 328 x 328 pixels
// symbol: 264 pixels wide at x = 32
// within 200 pixels, fits: False
// reason: noFit (exceedsMaxWidth)
}