Delphi DLL Requires Chilkat v11.7.0+
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
json: HCkJsonObject;
fmt: HCkFormats;
jsonOut: HCkJsonObject;
bdPng: HCkBinData;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'payload.text','https://www.chilkatsoft.com/');
CkJsonObject_UpdateInt(json,'render.moduleSize',6);
fmt := CkFormats_Create();
jsonOut := CkJsonObject_Create();
success := CkFormats_QrCode(fmt,'generate',json,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add(CkFormats__lastErrorText(fmt));
Exit;
end;
Memo1.Lines.Add('format: ' + CkJsonObject__stringOf(jsonOut,'outputs[0].format'));
Memo1.Lines.Add('MIME type: ' + CkJsonObject__stringOf(jsonOut,'outputs[0].mimeType'));
Memo1.Lines.Add('image: ' + IntToStr(CkJsonObject_IntOf(jsonOut,'outputs[0].width')) + ' x ' + IntToStr(CkJsonObject_IntOf(jsonOut,'outputs[0].height')) + ' pixels');
// outputs[0].base64 is the PNG file, base64 encoded.
bdPng := CkBinData_Create();
success := CkBinData_AppendEncoded(bdPng,CkJsonObject__stringOf(jsonOut,'outputs[0].base64'),'base64');
if (success = False) then
begin
Memo1.Lines.Add(CkBinData__lastErrorText(bdPng));
Exit;
end;
Memo1.Lines.Add('PNG bytes: ' + IntToStr(CkBinData_getNumBytes(bdPng)));
// The BinData holds the image. Here it is simply saved.
success := CkBinData_WriteFile(bdPng,'qa_output/qr_in_memory.png');
if (success = False) then
begin
Memo1.Lines.Add(CkBinData__lastErrorText(bdPng));
Exit;
end;
// The PNG held in bdPng:
//
// Sample output:
// format: png
// MIME type: image/png
// image: 222 x 222 pixels
// PNG bytes: 877
CkJsonObject_Dispose(json);
CkFormats_Dispose(fmt);
CkJsonObject_Dispose(jsonOut);
CkBinData_Dispose(bdPng);