Forum

Notifications
Clear all

QR Code Generator

1 Posts
1 Users
0 Reactions
239 Views
(@hackbart)
Posts: 24
Trusted Member
Topic starter
 

If you ever need to generate a QR code you might check the following project: https://github.com/jeromeetienne/jquery-qrcode
The usage is quite simple, create a qrCode class and render it into an element. For example like this. 

function generateQRCode(const AText: String): String;
begin
 asm
            var tempDiv = document.createElement("div");
            document.body.appendChild(tempDiv);
            var qrCode = new QRCode(tempDiv, {
                text: @AText,
                width: 256,
                height: 256,
                correctLevel: QRCode.CorrectLevel.H
            });

            setTimeout(() => {
                var qrImage = tempDiv.getElementsByTagName("img")[0];
                var canvas = document.createElement("canvas");
                document.body.appendChild(canvas);
                var context = canvas.getContext("2d");
                canvas.width = qrImage.width;
                canvas.height = qrImage.height;
                context.drawImage(qrImage, 0, 0);

                var base64Jpg = canvas.toDataURL("image/jpeg");
                @result = base64Jpg;

                canvas.remove();
                tempDiv.remove();
            }, 100);
  end;
end;
 
Posted : 07/06/2024 8:32 pm
Share: