Unicode C++ Requires Chilkat v11.7.0+
Unicode C++
Generate a QR Code PNG in Memory
See more QR Code Examples
Demonstrates getting a QR code image without writing a file. With no output options the result is a PNG returned as base64 in outputs[0].base64 of the response. The example decodes it into a BinData, which holds the bytes of the PNG to send in an HTTP response, store in a database, attach to an email, or save.Chilkat Unicode C++ Downloads
#include <CkJsonObjectW.h>
#include <CkFormatsW.h>
#include <CkBinDataW.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/");
json.UpdateInt(L"render.moduleSize",6);
CkFormatsW fmt;
CkJsonObjectW jsonOut;
success = fmt.QrCode(L"generate",json,jsonOut);
if (success == false) {
wprintf(L"%s\n",fmt.lastErrorText());
return;
}
wprintf(L"format: %s\n",jsonOut.stringOf(L"outputs[0].format"));
wprintf(L"MIME type: %s\n",jsonOut.stringOf(L"outputs[0].mimeType"));
wprintf(L"image: %d x %d pixels\n",jsonOut.IntOf(L"outputs[0].width"),jsonOut.IntOf(L"outputs[0].height"));
// outputs[0].base64 is the PNG file, base64 encoded.
CkBinDataW bdPng;
success = bdPng.AppendEncoded(jsonOut.stringOf(L"outputs[0].base64"),L"base64");
if (success == false) {
wprintf(L"%s\n",bdPng.lastErrorText());
return;
}
wprintf(L"PNG bytes: %d\n",bdPng.get_NumBytes());
// The BinData holds the image. Here it is simply saved.
success = bdPng.WriteFile(L"qa_output/qr_in_memory.png");
if (success == false) {
wprintf(L"%s\n",bdPng.lastErrorText());
return;
}
// The PNG held in bdPng:
//
// Sample output:
// format: png
// MIME type: image/png
// image: 222 x 222 pixels
// PNG bytes: 877
}