Sample code for 30+ languages & platforms
Delphi DLL Requires Chilkat v11.7.0+

QR Code Colors and Transparent Background

See more QR Code Examples

Demonstrates colored QR codes. render.foreground is the color of the dark modules and render.background the color behind them, each as #RRGGBB. Either can instead be an object with a color and an opacity from 0 to 1, and a background opacity of 0 gives a PNG with a transparent background to place over a page or a design. Readers need contrast: keep the modules clearly darker than whatever ends up behind them.

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
fmt: HCkFormats;
jsonOut: HCkJsonObject;
json: HCkJsonObject;
json2: HCkJsonObject;

begin
success := False;

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

fmt := CkFormats_Create();
jsonOut := CkJsonObject_Create();

//  Dark blue modules on a pale yellow background.
json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'payload.text','https://www.chilkatsoft.com/');
CkJsonObject_UpdateInt(json,'render.moduleSize',6);
CkJsonObject_UpdateString(json,'render.foreground','#1B3A6B');
CkJsonObject_UpdateString(json,'render.background','#FFF8DC');
CkJsonObject_UpdateString(json,'output.path','qa_output/qr_blue.png');
CkJsonObject_UpdateBool(json,'output.overwrite',True);
CkJsonObject_UpdateString(json,'output.return','none');
success := CkFormats_QrCode(fmt,'generate',json,jsonOut);
if (success = False) then
  begin
    Memo1.Lines.Add(CkFormats__lastErrorText(fmt));
    Exit;
  end;
Memo1.Lines.Add('colored: ' + CkJsonObject__stringOf(jsonOut,'outputs[0].path') + ', ' + IntToStr(CkJsonObject_IntOf(jsonOut,'outputs[0].byteCount')) + ' bytes');

//  The image written to qa_output/qr_blue.png:

//  image

//  The same modules on a fully transparent background.
json2 := CkJsonObject_Create();
CkJsonObject_UpdateString(json2,'payload.text','https://www.chilkatsoft.com/');
CkJsonObject_UpdateInt(json2,'render.moduleSize',6);
CkJsonObject_UpdateString(json2,'render.foreground','#1B3A6B');
CkJsonObject_UpdateString(json2,'render.background.color','#FFFFFF');
CkJsonObject_UpdateNumber(json2,'render.background.opacity','0');
CkJsonObject_UpdateString(json2,'output.path','qa_output/qr_transparent.png');
CkJsonObject_UpdateBool(json2,'output.overwrite',True);
CkJsonObject_UpdateString(json2,'output.return','none');
success := CkFormats_QrCode(fmt,'generate',json2,jsonOut);
if (success = False) then
  begin
    Memo1.Lines.Add(CkFormats__lastErrorText(fmt));
    Exit;
  end;
Memo1.Lines.Add('transparent: ' + CkJsonObject__stringOf(jsonOut,'outputs[0].path') + ', ' + IntToStr(CkJsonObject_IntOf(jsonOut,'outputs[0].byteCount')) + ' bytes');

//  qa_output/qr_transparent.png, placed here over a checkerboard and over a colored page
//  to show that whatever is behind the image shows through:

//  image

//  Sample output:

//  colored: qa_output/qr_blue.png, 1345 bytes
//  transparent: qa_output/qr_transparent.png, 1377 bytes

CkFormats_Dispose(fmt);
CkJsonObject_Dispose(jsonOut);
CkJsonObject_Dispose(json);
CkJsonObject_Dispose(json2);