大家有没有用过Photoshop,他进行区域选择时,选择框是流动的线。
Delphi的Image Editor进行选择时,也是这种流动线
请问这种选择流动线是怎么实现的,提个思路。

解决方案 »

  1.   

    //在《CSDN开发高手》上看到的一篇文章,自己改了改~~unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, StdCtrls;type
      TForm1 = class(TForm)
        Timer1: TTimer;
        Button1: TButton;
        procedure Timer1Timer(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { private declarations }
        FPathPoints: array of TPoint;
        FPathTypes: array of Byte;
        FNumber: Integer;
        FCounter: Byte;
      public
        { public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure MovingDots(X, Y: Integer; mForm: TForm1); stdcall;
    begin
      if mForm.FCounter = 15 then mForm.FCounter := 0;
      if mForm.FCounter < 5 then
        mForm.Canvas.Pixels[X, Y] := clWhite
      else if mForm.FCounter < 12 then
        mForm.Canvas.Pixels[X, Y] := clRed
      else mForm.Canvas.Pixels[X, Y] := clBlue;
      Inc(mForm.FCounter);
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    var
      J, K: Integer;
    begin
      for J := 0 to Pred(FNumber) do begin
        if FPathTypes[J] = PT_CLOSEFIGURE or PT_LINETO then begin
          for K := J downto 0 do
            if FPathTypes[K] = PT_MOVETO then begin
              LineDDA(FPathPoints[J].X, FPathPoints[J].Y,
                FPathPoints[K].X, FPathPoints[K].Y, @MovingDots, Longint(self));
              Break;
            end;
          Continue;
        end;
        LineDDA(FPathPoints[J].X, FPathPoints[J].Y,
          FPathPoints[J + 1].X, FPathPoints[J + 1].Y, @MovingDots, Longint(self));
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      Canvas.Font.Name := '幼圆';
      Canvas.Font.Style := [fsItalic, fsBold];
      Canvas.Font.Size := 72;
      BeginPath(Canvas.Handle);
      SetBkMode(Canvas.Handle, TRANSPARENT);
      Canvas.TextOut(120, 20, '电脑');
      Canvas.Rectangle(Rect(10, 10, 100, 100));
      EndPath(Canvas.Handle);
      if not FlattenPath(Canvas.Handle) then Exit;
      FNumber := GetPath(Canvas.Handle, Pointer(nil^), Pointer(nil^), 0);
      SetLength(FPathPoints, FNumber);
      SetLength(FPathTypes, FNumber);
      FNumber := GetPath(Canvas.Handle, FPathPoints[0], FPathTypes[0], FNumber);
      Timer1.Enabled := True;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      Timer1.Enabled := False;
      Timer1.Interval := 100;
    end;end.
      

  2.   

    楼主说的是 “蚂蚁线” 的选择效果,我这里有篇以前收集的酷文,讲的就是这个,马上你就可以用。/////////////////////原文////////////////////////////////
    来自:卷起千堆雪tyn, 时间:2001-12-24 22:10:00, ID:809383 
    YB老弟说我没有诚意,唉,那我就来点诚意,无私一把,给大家一点小小技巧----关于蚂蚁线>以下程序在一个表单上放置一个Timer控件,设置Interval :=100;
    >实现PhotoShop里的流动线效果.
    >以下程序字节数<512,简练,高效;原来PhotoShop也不过如此~~unit n;interfaceuses
      Windows,Forms,Graphics,Classes,ExtCtrls;type
      TF=class(TForm)
        m:TTimer;
        procedure mTimer(Sender:TObject);
      end;var
      F:TF;
      a:Byte;implementation{$R *.DFM}procedure c(X,Y:Integer;t:TCanvas);stdcall;
    begin
      a:=a shl 1;
      if a =0 then a:=1;
      if (a and 224)>0 then
        t.Pixels[X,Y]:=clWhite
      else
        t.Pixels[X,Y]:=clBlack;
    end;procedure TF.mTimer(Sender:TObject);
    begin
      LineDDA(0,0,333,333,@c,LongInt(Canvas));
    end;end.>运行之后,有没有看见象蚂蚁在爬呢?      最后祝所有的DFW象爬动的蚂蚁般幸福快乐 .