请问高手 做分层的IMAGE 如何做 如何动态捕捉用CANVAS画的线条 就是如何选中单个的 像PHOTOSHOP里的层的概念差不多

解决方案 »

  1.   

    基本同意yewangqing的说法,
        不过:记录各个图形的位置目的何在?是为了点击只用吗?那是否还要判断用户点击时的鼠标位置?    是否可以将canvas画的每个图元当作一个对象,点击这个图元就可以得到其句柄。
      

  2.   

    http://expert.csdn.net/Expert/topic/1904/1904043.xml?temp=.7446405迷茫请指教
      

  3.   

    这里有一个自己写小程序,供大家参考,欢迎交流!!!unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,StdCtrls;const
      maxIndex=5;         //直线个数type
      LineRec=record
        x1,y1,x2,y2:Integer;        //记录直线两端坐标
        Color:TColor;               //记录直线颜色
      end;type
      TForm1 = class(TForm)
        procedure DrawLine(Index:Integer);  //划线
        procedure EraseLine(Index:Integer);   //擦线
        procedure FormCreate(Sender: TObject);
        procedure FormActivate(Sender: TObject);
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
          Y: Integer);
        procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
        LineArray:array[0..maxIndex - 1] of LineRec;    //直线数组
        procedure createLabel(LI,Lx1,Lx2,Ly1,Ly2:Integer);   //产生直线对应LABEL
      public
        { Public declarations }
        XOldSet,YOldSet:Integer; //移动前坐标
        Dragging:Boolean;        //是否拖动标志
        LabelIndex:Integer;      //当前选择的直线LABEL号
        LineLabel:array[0..maxIndex - 1] of TLabel;   //LABEL数组
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DrawLine(Index:Integer);
    begin
      with Canvas,LineArray[Index] do
      begin
        Pen.Color:=Color;
        MoveTo(x1,y1);
        LineTo(x2,y2);
      end;
    end;procedure TForm1.EraseLine(Index:Integer);
    begin
      with Canvas,LineArray[Index] do
      begin
        Pen.Color:=GetBKColor(Handle);
        MoveTo(x1,y1);
        LineTo(x2,y2);
      end;
    end;procedure TForm1.CreateLabel(LI,Lx1,Lx2,Ly1,Ly2:Integer);
    begin
      LineLabel[LI]:=TLabel.Create(Form1);
      LineLabel[LI].Name:='Label'+IntToStr(LI);
      LineLabel[LI].Left:=Lx2;
      LineLabel[LI].Top:=Ly2;
      LineLabel[LI].Color:=clGreen;
      LineLabel[LI].Caption:='X1:'+IntToStr(Lx1)+',Y1:'+IntToStr(Ly1)+',X2:'
        +IntToStr(Lx2)+',Y2:'+IntToStr(Ly2);
      Form1.InsertControl(LineLabel[LI]);
      LineLabel[LI].OnMouseDown:=Form1.OnMouseDown;
      LineLabel[LI].OnMouseMove:=Form1.OnMouseMove;
      LineLabel[LI].OnMouseUp:=Form1.OnMouseUp;
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
      I:Integer;
    begin
      Dragging:=False;
      for i:=0 to maxIndex - 1 do
      begin
        with LineArray[I] do
        begin
          x1:=Random(120+I*30);
          x2:=Random(152+I*30);
          y1:=Random(240+I*30);
          y2:=Random(382+I*30);
          Color:=RGB(Random(256),Random(256),Random(256));
         end;
      end;
    end;procedure TForm1.FormActivate(Sender: TObject);
    var
      I:Integer;
    begin
       for I:=0 to maxIndex - 1 do
       begin
         with LineArray[I] do
           CreateLabel(I,x1,x2,y1,y2);
         DrawLine(I);
       end;
    end;procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    var
      I:Integer;
    begin
      for I:=0 to maxIndex - 1 do
        if Sender=LineLabel[I] then
        begin
          XOldSet:=X;
          YOldSet:=Y;
          LabelIndex:=I;
          break;
        end;
      Dragging:=True;
    end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      if Dragging then
        begin
          with LineArray[LabelIndex],LineLabel[LabelIndex] do
          begin
            Left:=x2+(X - XOldSet);
            TOP:=Y2+(Y - YOldSet);
            EraseLine(LabelIndex);
            x1:=x1+(X - XOldSet);
            x2:=x2+(X - XOldSet);
            y1:=y1+(Y - YOldSet);
            y2:=y2+(Y - YOldSet);
            DrawLine(LabelIndex);
            LineLabel[LabelIndex].Caption:='X1:'+IntToStr(x1)+',Y1:'+IntToStr(y1)+',X2:'
               +IntToStr(x2)+',Y2:'+IntToStr(y2);
          end;
        end;
    end;procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      Dragging:=False;
      with LineArray[LabelIndex] do
      begin
        x1:=x1+(X - XOldSet);
        x2:=x2+(X - XOldSet);
        y1:=y1+(Y - YOldSet);
        y2:=y2+(Y - YOldSet);
      end;
    end;end.〔naturalym〕
      

  4.   

    textout写上的字符串如何擦除?
      

  5.   

    我有一个简单的例子,发邮件给我索取吧。
    [email protected]
      

  6.   

    我不知道你具体想怎么做!但如果只是划出的线段能用鼠标选中的话,这个问题我能帮你解决,很简单的!如果需要发邮件向我索取好了,[email protected]