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

Generate a QR Code with the Barcode Method

See more QR Code Examples

Demonstrates the Barcode method, which is the general form of QrCode: the request names the symbology, and everything else is the same. QrCode is Barcode with the symbology already set to qr, and identical requests to the two methods give identical results. A program that will produce more than one kind of barcode can use Barcode for all of them.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkFormats.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    success.i = 0

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

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"symbology","qr")
    CkJsonObject::ckUpdateString(json,"payload.text","https://www.chilkatsoft.com/")
    CkJsonObject::ckUpdateString(json,"output.path","qa_output/qr_from_barcode.png")
    CkJsonObject::ckUpdateBool(json,"output.overwrite",1)
    CkJsonObject::ckUpdateString(json,"output.return","none")

    fmt.i = CkFormats::ckCreate()
    If fmt.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    jsonOut.i = CkJsonObject::ckCreate()
    If jsonOut.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkFormats::ckBarcode(fmt,"generate",json,jsonOut)
    If success = 0
        Debug CkFormats::ckLastErrorText(fmt)
        CkJsonObject::ckDispose(json)
        CkFormats::ckDispose(fmt)
        CkJsonObject::ckDispose(jsonOut)
        ProcedureReturn
    EndIf

    Debug "symbology: " + CkJsonObject::ckStringOf(jsonOut,"symbols[0].symbology")
    Debug "QR version: " + Str(CkJsonObject::ckIntOf(jsonOut,"symbols[0].selectedEncoding.version"))
    Debug "image: " + Str(CkJsonObject::ckIntOf(jsonOut,"outputs[0].width")) + " x " + Str(CkJsonObject::ckIntOf(jsonOut,"outputs[0].height")) + " pixels"

    ;  The image written to qa_output/qr_from_barcode.png:

    ;  image

    ;  Barcode requires the symbology.  QrCode does not.
    json2.i = CkJsonObject::ckCreate()
    If json2.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json2,"payload.text","https://www.chilkatsoft.com/")
    success = CkFormats::ckBarcode(fmt,"generate",json2,jsonOut)
    If success = 0
        Debug "without a symbology: " + CkJsonObject::ckStringOf(jsonOut,"errors[0].code") + " at " + CkJsonObject::ckStringOf(jsonOut,"errors[0].path")
    EndIf

    ;  Sample output:

    ;  symbology: qr
    ;  QR version: 3
    ;  image: 148 x 148 pixels
    ;  without a symbology: missingOption at /symbology


    CkJsonObject::ckDispose(json)
    CkFormats::ckDispose(fmt)
    CkJsonObject::ckDispose(jsonOut)
    CkJsonObject::ckDispose(json2)


    ProcedureReturn
EndProcedure