Visual FoxPro Requires Chilkat v11.7.0+
Visual FoxPro
QR Code with Non-English Text (UTF-8 and ECI)
See more QR Code Examples
Demonstrates text outside ASCII. QrCode always stores text as UTF-8 bytes, which is what phones expect. A QR code can also say so explicitly with an ECI header: setting encoding.eci to 26 declares the bytes to be UTF-8, for readers that would otherwise assume another character set. The header costs a little space, and a few older readers do not understand it, so it is off by default.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loSbText
LOCAL loJson
LOCAL loFmt
LOCAL loJsonOut
lnSuccess = 0
* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
* The text is "Gruesse aus Muenchen" written with u-umlaut and sharp s. It is given here with
* JSON escapes only so that this source is plain ASCII. Decode turns the escapes into characters.
loSbText = CreateObject('Chilkat.StringBuilder')
loSbText.Append("Gr\u00fc\u00dfe aus M\u00fcnchen")
loSbText.Decode("json","utf-8")
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateSb("payload.text",loSbText)
loJson.UpdateString("output.path","qa_output/qr_utf8.png")
loJson.UpdateBool("output.overwrite",1)
loJson.UpdateString("output.return","none")
loFmt = CreateObject('Chilkat.Formats')
loJsonOut = CreateObject('Chilkat.JsonObject')
lnSuccess = loFmt.QrCode("generate",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
? loFmt.LastErrorText
RELEASE loSbText
RELEASE loJson
RELEASE loFmt
RELEASE loJsonOut
CANCEL
ENDIF
* 17 characters, three of which take two bytes in UTF-8.
? "characters: " + STR(loSbText.Length)
? "bytes encoded: " + STR(loJsonOut.IntOf("symbols[0].payloadBytes"))
? "ECI header: " + STR(loJsonOut.HasMember("symbols[0].selectedEncoding.eci"))
* Without an ECI header (qa_output/qr_utf8.png):
*
* The same text with an ECI header declaring UTF-8.
loJson.UpdateInt("encoding.eci",26)
loJson.UpdateString("output.path","qa_output/qr_utf8_eci.png")
lnSuccess = loFmt.QrCode("generate",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
? loFmt.LastErrorText
RELEASE loSbText
RELEASE loJson
RELEASE loFmt
RELEASE loJsonOut
CANCEL
ENDIF
? "with encoding.eci = 26, ECI header: " + STR(loJsonOut.HasMember("symbols[0].selectedEncoding.eci")) + ", value " + STR(loJsonOut.IntOf("symbols[0].selectedEncoding.eci"))
* With the ECI header (qa_output/qr_utf8_eci.png). Both scan as the same text:
*
* Sample output:
* characters: 17
* bytes encoded: 20
* ECI header: False
* with encoding.eci = 26, ECI header: True, value 26
RELEASE loSbText
RELEASE loJson
RELEASE loFmt
RELEASE loJsonOut