Code: Select all
USING Gma.QrCodeNet.Encoding
USING Gma.QrCodeNet.Encoding.Windows.Render
USING System.IO
USING System.Drawing
USING System.Drawing.Imaging
CLASS TestQrCode
METHOD Generate(cText AS STRING, nSize AS WORD, cType AS STRING, cFile AS STRING) AS LOGIC PASCAL CLASS TestQrCode
// cText Zu codierender Text
// nSize QRCode Größe 1-255
// cType Output Filetyp PNG, BMP, JPEG
// cFile Output Filename inkl. Pfad ohne Extension
// Return true/false
LOCAL qrEncoder AS QREncoder
LOCAL qrCode AS QrCode
LOCAL renderer AS GraphicsRenderer
LOCAL format AS ImageFormat
LOCAL cOutput AS STRING
IF Empty(cText) .or. nSize < 1
RETURN FALSE
ENDIF
DO CASE
CASE Lower(cType) == "png"
format := ImageFormat.Png
cOutput := cFile + ".png"
CASE Lower(cType) == "bmp"
format := ImageFormat.Bmp
cOutput := cFile + ".bmp"
OTHERWISE
format := ImageFormat.Jpeg
cOutput := cFile + ".jpg"
ENDCASE
FErase(cOutput)
qrEncoder := QrEncoder{ErrorCorrectionLevel.H}
qrCode := qrEncoder:Encode(cText)
renderer := GraphicsRenderer{FixedModuleSize{nSize, QuietZoneModules.Two}, System.Drawing.Brushes.Black, System.Drawing.Brushes.White}
BEGIN USING VAR stream := FileStream{cOutput, FileMode.Create}
renderer:WriteToStream(qrCode:Matrix, format, stream)
END USING
RETURN iif(File(cOutput), TRUE, FALSE)
END CLASS