How to replace Bitmap.ClearRect from FMX replace on VCL?

69 views Asked by At

I try to rewrite an FMX project in VCL.

Code for QR-code drawing in FMX:

for Column := 0 to QRCode.Columns - 1 do
begin
  if QRCode.IsBlack[Row, Column] then
    QRCodeBitmap.ClearRect(TRectF.Create(PointF(Column, Row) * Scale,
      Scale, Scale), TAlphaColors.Black);
end;

How to replace QRCodeBitmap.ClearRect() in VCL?

I try like this:

if (QRCode.IsBlack[Row, Column]) then
begin
  QRCodeBitmap.Canvas.Pixels[Column, Row] := clBlack;
end else
begin
  QRCodeBitmap.Canvas.Pixels[Column, Row] := clWhite;
end; 

but it does not work like I want.

1

There are 1 answers

0
Remy Lebeau On

The TBitmap.ClearRect() method in FMX fills a rectangular area with a color.

In VCL, you can do the same thing using the TBitmap.Canvas.FillRect() method, where the fill color is specified in the TBitmap.Canvas.Brush.Color property, eg:

for Column := 0 to QRCode.Columns - 1 do
begin
  if QRCode.IsBlack[Row, Column] then
  begin
    QRCodeBitmap.Canvas.Brush.Color := clBlack;
    QRCodeBitmap.Canvas.FillRect(TRect.Create(Point(Column * Scale, Row * Scale),
      Scale, Scale));
  end;
end;