uses
   vcl.Graphics, DelphiZXingQRCode;

procedure CreateQRCode(AImg: vcl.Graphics.TBitMap; const ACode: String);
const
  IMG_SCALE = 25; //放大倍数
var
  QRCode: TDelphiZXingQRCode;
  Row, Column: Integer;
begin
  if (AImg = nil) or (Trim(ACode) = '') then Exit;

  QRCode := TDelphiZXingQRCode.Create;
  try
    QRCode.Data := ACode;
    QRCode.Encoding := TQRCodeEncoding(qrUTF8BOM);
    QRCode.QuietZone := 1;
    QRCode.Data := ACode;

    AImg.Height := QRCode.Rows * IMG_SCALE;
    AImg.Width := QRCode.Columns * IMG_SCALE;

    AImg.Canvas.Lock;
    AImg.Canvas.Brush.Color := clWhite;
    AImg.Canvas.FillRect(Rect(0, 0, AImg.Width, AImg.Height));
    AImg.Canvas.Brush.Color := clBlack;
    for Row := 0 to QRCode.Rows - 1 do
      for Column := 0 to QRCode.Columns - 1 do
        if QRCode.IsBlack[Row, Column] then
        begin
          AImg.Canvas.FillRect(Rect(Column * IMG_SCALE,  Row * IMG_SCALE,
            Column * IMG_SCALE + IMG_SCALE, Row * IMG_SCALE + IMG_SCALE));
        end;
    AImg.Canvas.Unlock;
  finally
    QRCode.Free;
  end;
end;

 

相关文章:

  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2021-12-02
  • 2021-06-25
猜你喜欢
  • 2021-12-01
  • 2021-12-16
  • 2021-12-26
  • 2021-04-08
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
相关资源
相似解决方案