Programming Delphi Draw a flowing line like photoshop selection tools
Notice: Undefined variable: relatedArticlesCount in /home/wwwroot/codeback.net/plugins/content/tags.php on line 149
Tags:

Have you ever used photoshop? When you use the selection tool to select a region in the picture, a flowing line would appear around the selection area. Do you want to realize this function in your programs?

This is an example written by Delphi, you could convert it to other language as your need.

Put a timer component to the from, then assign the following codes.

var
  LineStep: Byte;

implementation

{$R *.DFM}

procedure DrawFlowLine(X, Y: Integer; Canvas: TCanvas); stdcall;
begin
  LineStep := LineStep shl 1;

  if LineStep = 0 then
    LineStep := 1;

  if (LineStep and 240) > 0 then
    Canvas.Pixels[X,Y] := clWhite
  else
    Canvas.Pixels[X,Y] := clBlack;
end;

procedure TForm1.Timer1Timer(Sender:TObject);
begin
  LineDDA(0, 0, 358, 371, @DrawFlowLine, LongInt(Canvas));
end;

Run the program, see what happen. This is a static flowing line, to make it move, you need to alternate the pixels everytime when timer1 is triggered.


Add comment


Security code
Refresh

Programming - Delphi