QRCodeBitmap: TfgBitmap;
procedure TFormMain.UpdateQR;
var
QRCode: TDelphiZXingQRCode;
pixelColor: TAlphaColor;
Row, Column: integer;
y, x: integer;
columnPixel, rowPixel, pixelCount: single;
function GetPixelCount(AWidth, AHeight: single): single;
begin
if QRCode.Rows > 0 then
Result := (Trunc(Min(AWidth, AHeight)) div QRCode.Rows) * TfgAndroidHelper.ScreenScale
else
Result := 0;
end;
begin
TfgAssert.IsNotNil(QRCodeBitmap, 'QRCodeBitmap is nil UpdateQR');
QRCode := TDelphiZXingQRCode.Create;
try
QRCode.Data := ' ' + QRCodeText;
QRCode.Encoding := qrAuto;
QRCode.QuietZone := 1;
pixelCount := GetPixelCount(imgQRCode.Width, imgQRCode.Height);
QRCodeBitmap.Size := TSizeF.Create(QRCode.Rows * pixelCount,
QRCode.Columns * pixelCount).Round;
QRCodeBitmap.Canvas.Stroke.Kind := TfgBrushKind.Solid;
QRCodeBitmap.Canvas.Fill.Kind := TfgBrushKind.Solid;
for Row := 0 to QRCode.Rows - 1 do
begin
for Column := 0 to QRCode.Columns - 1 do
begin
if (QRCode.IsBlack[Row, Column]) then
pixelColor := TAlphaColorRec.Black
else
pixelColor := TAlphaColorRec.White;
columnPixel := Column * pixelCount;
rowPixel := Row * pixelCount;
QRCodeBitmap.Canvas.Fill.Color := pixelColor;
QRCodeBitmap.Canvas.Stroke.Color := pixelColor;
QRCodeBitmap.Canvas.FillRect(columnPixel, rowPixel, columnPixel + pixelCount, rowPixel + pixelCount);
end;
end;
finally
QRCode.Free;
end;
end;