Delphi ActiveX Requires Chilkat v11.7.0+
Delphi ActiveX
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 ActiveX Downloads
var
success: Integer;
json: TChilkatJsonObject;
fmt: TChilkatFormats;
jsonOut: TChilkatJsonObject;
bdPng: TChilkatBinData;
begin
success := 0;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
json := TChilkatJsonObject.Create(Self);
json.UpdateString('payload.text','https://www.chilkatsoft.com/');
json.UpdateInt('render.moduleSize',6);
fmt := TChilkatFormats.Create(Self);
jsonOut := TChilkatJsonObject.Create(Self);
success := fmt.QrCode('generate',json.ControlInterface,jsonOut.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(fmt.LastErrorText);
Exit;
end;
Memo1.Lines.Add('format: ' + jsonOut.StringOf('outputs[0].format'));
Memo1.Lines.Add('MIME type: ' + jsonOut.StringOf('outputs[0].mimeType'));
Memo1.Lines.Add('image: ' + IntToStr(jsonOut.IntOf('outputs[0].width')) + ' x ' + IntToStr(jsonOut.IntOf('outputs[0].height')) + ' pixels');
// outputs[0].base64 is the PNG file, base64 encoded.
bdPng := TChilkatBinData.Create(Self);
success := bdPng.AppendEncoded(jsonOut.StringOf('outputs[0].base64'),'base64');
if (success = 0) then
begin
Memo1.Lines.Add(bdPng.LastErrorText);
Exit;
end;
Memo1.Lines.Add('PNG bytes: ' + IntToStr(bdPng.NumBytes));
// The BinData holds the image. Here it is simply saved.
success := bdPng.WriteFile('qa_output/qr_in_memory.png');
if (success = 0) then
begin
Memo1.Lines.Add(bdPng.LastErrorText);
Exit;
end;
// The PNG held in bdPng:
//
// Sample output:
// format: png
// MIME type: image/png
// image: 222 x 222 pixels
// PNG bytes: 877