Jump to content

how to generate QRCode with unigui ?


devya

Recommended Posts

Here is my unigui qr code generator

You will need DelphiZXingQRCode though

procedure TUniMainModule.CreateTicketQRCode(const ATicketId, ATicketUrl: string);

  procedure ResizeBitmap(Bitmap: TBitmap; const NewWidth, NewHeight: integer);
  var
    buffer: TBitmap;
  begin
    buffer := TBitmap.Create;
    try
      buffer.SetSize(NewWidth, NewHeight);
      buffer.Canvas.StretchDraw(Rect(0, 0, NewWidth, NewHeight), Bitmap);
      Bitmap.SetSize(NewWidth, NewHeight);
      Bitmap.Canvas.Draw(0, 0, buffer);
    finally
      buffer.Free;
    end;
  end;

var
  QRCodeBitmap: TBitmap;
  QRCode: TDelphiZXingQRCode;
  Row, Column: Integer;
  PNG: TPNGImage;
begin
  if UniServerModule.ConfigINI.QRCodeSaveDir = '' then
    Exit;

  QRCodeBitmap := nil;
  QRCode := nil;
  PNG := nil;
  try
    QRCodeBitmap := TBitmap.Create;
    QRCode := TDelphiZXingQRCode.Create;
    QRCode.Data := ATicketUrl;
    QRCodeBitmap.SetSize(QRCode.Rows, QRCode.Columns);
    for Row := 0 to QRCode.Rows - 1 do
    begin
      for Column := 0 to QRCode.Columns - 1 do
      begin
        if (QRCode.IsBlack[Row, Column]) then
        begin
          QRCodeBitmap.Canvas.Pixels[Column, Row] := clBlack;
        end else
        begin
          QRCodeBitmap.Canvas.Pixels[Column, Row] := clWhite;
        end;
      end;
    end;
    ResizeBitmap(QRCodeBitmap, QRCode.Rows*5, QRCode.Columns*5);
    PNG := TPNGImage.Create;
    PNG.Assign(QRCodeBitmap);
    PNG.SaveToFile(TPath.Combine(UniServerModule.ConfigINI.QRCodeSaveDir, LowerCase(ATicketId)+'.png'));
  finally
    QRCodeBitmap.Free;
    QRCode.Free;
    PNG.Free;
  end;
end;
 

 

Link to comment
Share on other sites

  • 3 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...