Search code examples
delphidrawdelphi-10.1-berlintcanvas

Drawing a borderline of dots around a TBitmap?


I have written a routine which should add a dotted border to a bitmap:

procedure AddDottedBorderToBitmap(aBM: Vcl.Graphics.TBitmap);
var
  c: TCanvas;
begin
  c := aBM.Canvas;
  c.Pen.Color := clBlack;
  c.Pen.Mode  := pmXor;
  c.Pen.Style := psDot;

  c.MoveTo(0, 0);
  c.LineTo(0, aBM.Height - 1);
  c.LineTo(aBM.Width - 1, aBM.Height - 1);
  c.LineTo(aBM.Width - 1, 0);
  c.LineTo(0, 0);
end;

But when enlarging the result, the resulting borderline instead of dots seems to be made of small dashes:

enter image description here

Is this correct? If not, how can I get real dots instead of dashes?


Solution

  • DrawFocusRect it's a Windows API call that make a border like you need.

    procedure AddDottedBorderToBitmap(aBM: Vcl.Graphics.TBitmap);
    begin
      DrawFocusRect(aBM.canvas.Handle,Rect(0,0,aBM.Width,aBM.Height));
    end;