C Requires Chilkat v11.7.0+
C
Create a vCard (Contact) QR Code
See more QR Code Examples
Demonstrates a QR code that adds a contact to a phone when scanned. The text is a vCard, the standard format for contact details: lines between BEGIN:VCARD and END:VCARD, each ending with CRLF. A vCard is fairly long, so the symbol is larger than one holding a web address. Leave out the fields that are not needed to keep it small.Chilkat C Downloads
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>
#include <C_CkFormats.h>
void ChilkatSample(void)
{
BOOL success;
HCkStringBuilder sbCard;
HCkJsonObject json;
HCkFormats fmt;
HCkJsonObject jsonOut;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The second argument of AppendLine is cktrue to end each line with CRLF.
sbCard = CkStringBuilder_Create();
CkStringBuilder_AppendLine(sbCard,"BEGIN:VCARD",TRUE);
CkStringBuilder_AppendLine(sbCard,"VERSION:3.0",TRUE);
CkStringBuilder_AppendLine(sbCard,"N:Smith;Alex;;;",TRUE);
CkStringBuilder_AppendLine(sbCard,"FN:Alex Smith",TRUE);
CkStringBuilder_AppendLine(sbCard,"ORG:Example Company",TRUE);
CkStringBuilder_AppendLine(sbCard,"TITLE:Sales Manager",TRUE);
CkStringBuilder_AppendLine(sbCard,"TEL;TYPE=CELL:+1-555-0100",TRUE);
CkStringBuilder_AppendLine(sbCard,"EMAIL:alex.smith@example.com",TRUE);
CkStringBuilder_AppendLine(sbCard,"URL:https://www.example.com",TRUE);
CkStringBuilder_AppendLine(sbCard,"END:VCARD",TRUE);
json = CkJsonObject_Create();
CkJsonObject_UpdateSb(json,"payload.text",sbCard);
CkJsonObject_UpdateInt(json,"render.moduleSize",6);
CkJsonObject_UpdateString(json,"output.path","qa_output/qr_vcard.png");
CkJsonObject_UpdateBool(json,"output.overwrite",TRUE);
CkJsonObject_UpdateString(json,"output.return","none");
fmt = CkFormats_Create();
jsonOut = CkJsonObject_Create();
success = CkFormats_QrCode(fmt,"generate",json,jsonOut);
if (success == FALSE) {
printf("%s\n",CkFormats_lastErrorText(fmt));
CkStringBuilder_Dispose(sbCard);
CkJsonObject_Dispose(json);
CkFormats_Dispose(fmt);
CkJsonObject_Dispose(jsonOut);
return;
}
printf("vCard length: %d\n",CkStringBuilder_getLength(sbCard));
printf("QR version: %d\n",CkJsonObject_IntOf(jsonOut,"symbols[0].selectedEncoding.version"));
printf("modules: %d x %d\n",CkJsonObject_IntOf(jsonOut,"symbols[0].dimensions.modulesWide"),CkJsonObject_IntOf(jsonOut,"symbols[0].dimensions.modulesHigh"));
printf("image: %d x %d pixels\n",CkJsonObject_IntOf(jsonOut,"outputs[0].width"),CkJsonObject_IntOf(jsonOut,"outputs[0].height"));
// The image written to qa_output/qr_vcard.png:
//
// Sample output:
// vCard length: 197
// QR version: 10
// modules: 57 x 57
// image: 390 x 390 pixels
CkStringBuilder_Dispose(sbCard);
CkJsonObject_Dispose(json);
CkFormats_Dispose(fmt);
CkJsonObject_Dispose(jsonOut);
}