Visual Basic 6.0 Requires Chilkat v11.7.0+
Visual Basic 6.0
QR Code with a Physical Size in Millimeters at a Printer DPI
See more QR Code Examples
Demonstrates sizing a QR code for print. With render.units set to mm (or in, or pt) the module size is a physical length, and render.dpi says how many pixels the printer or the image has per inch. A module is always a whole number of pixels, because modules of uneven width scan badly, so the size asked for is rounded to the nearest pixel and the response reports the size actually used. The PNG records the dpi, so software that honors it prints the image at that physical size.Chilkat Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' This example requires the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.
Dim json As New ChilkatJsonObject
success = json.UpdateString("payload.text","https://www.chilkatsoft.com/")
' Modules of 0.5 mm, for a 300 dpi printer.
success = json.UpdateString("render.units","mm")
success = json.UpdateNumber("render.moduleSize","0.5")
success = json.UpdateInt("render.dpi",300)
success = json.UpdateString("output.path","qa_output/qr_300dpi.png")
success = json.UpdateBool("output.overwrite",1)
success = json.UpdateString("output.return","none")
Dim fmt As New ChilkatFormats
Dim jsonOut As New ChilkatJsonObject
success = fmt.QrCode("generate",json,jsonOut)
If (success = 0) Then
Debug.Print fmt.LastErrorText
Exit Sub
End If
' 0.5 mm at 300 dpi is 5.9 pixels, so each module is drawn 6 pixels wide.
Debug.Print "requested module: " & jsonOut.StringOf("measurements[0].requestedPitch") & " pixels"
Debug.Print "module drawn: " & jsonOut.IntOf("measurements[0].pitch") & " pixels = " & jsonOut.StringOf("measurements[0].moduleSize") & " mm"
Debug.Print "size was rounded: " & jsonOut.BoolOf("measurements[0].pitchAdjusted")
Debug.Print "image: " & jsonOut.IntOf("measurements[0].canvasWidth") & " x " & jsonOut.IntOf("measurements[0].canvasHeight") & " pixels"
Debug.Print "printed size: " & jsonOut.StringOf("measurements[0].physicalWidth") & " x " & jsonOut.StringOf("measurements[0].physicalHeight") & " mm"
' The image. A web page shows it pixel for pixel. Printed at 300 dpi it is 18.8 mm wide:
'
' When the exact size matters more than getting an image, requireExactPitch makes a size
' that is not a whole number of pixels a failure (noFit) instead of rounding it.
success = json.UpdateBool("render.requireExactPitch",1)
success = fmt.QrCode("generate",json,jsonOut)
If (success = 0) Then
Debug.Print "requireExactPitch: " & jsonOut.StringOf("errors[0].code") & " (" & jsonOut.StringOf("errors[0].message") & ")"
End If
' Sample output:
' requested module: 5.905512 pixels
' module drawn: 6 pixels = 0.508 mm
' size was rounded: True
' image: 222 x 222 pixels
' printed size: 18.796 x 18.796 mm
' requireExactPitch: noFit (the symbol does not fit the render constraints: pitchAdjusted)