UnitFormCanvas.~pas
上传用户:conquerdj
上传日期:2022-07-08
资源大小:417k
文件大小:23k
源码类别:

GDI/图象编程

开发平台:

Delphi

  1. unit UnitFormCanvas;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, ExtCtrls,StdCtrls;
  6. type
  7.   TFormCanvas = class(TForm)
  8.     Image1: TImage;
  9.     Image2: TImage;
  10.     CursorColor: TShape;
  11.     Imagecopy: TImage;
  12.     procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
  13.       Shift: TShiftState; X, Y: Integer);
  14.     procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  15.       Y: Integer);
  16.     procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
  17.       Shift: TShiftState; X, Y: Integer);
  18.     procedure FormShow(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.   public
  22.     { Public declarations }
  23.   end;
  24. var
  25.   FormCanvas: TFormCanvas;
  26.   //图元的起点数组
  27.   mStartPoint :TPoint;
  28.   //图元的终点数组
  29.   mEndPoint   :TPoint;
  30.   //鼠标移动过程中前一个点的坐标
  31.   mMovePrePoint: TPoint;
  32.   //用于保存图象或向Image1拷贝图象
  33.   Bitmap:Tbitmap;
  34. implementation
  35. uses UnitPaintbrush,UnitTxt;
  36. {$R *.dfm}
  37. //响应image1的鼠标下压事件
  38. procedure TFormCanvas.Image1MouseDown(Sender: TObject;
  39.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  40. begin
  41.   //判断是否为右键下压
  42.   if(Button=mbRight)then
  43.   begin
  44.     if(FormPaintBrush.Visible=true)then
  45.        FormPaintBrush.Visible:=false
  46.     else
  47.        FormPaintBrush.Visible:=true;
  48.   end;
  49.   //判断是否为左键下压
  50.   if(Button=mbLeft) and (mType<>0)then
  51.   begin
  52.     //保存图元的起点坐标
  53.     mStartPoint.x:=X;
  54.     mStartPoint.y:=Y;
  55.     //保存当前点坐标到mMovePrePoint变量中,以便鼠标移动时第一次消除用。
  56.     mMovePrePoint.x:=x;
  57.     mMovePrePoint.y:=y;
  58.     //取色
  59.     if(mType=10) then
  60.     begin
  61.        //将CursorColor显示出来
  62.        FormCanvas.CursorColor.Show;
  63.        //设置Shape组件的颜色
  64.        FormPaintbrush.Shape1.Brush.Color:=Canvas.Pixels[X,Y];
  65.        //取出颜色在颜色框里显示出来
  66.        //FormPaintbrush.ColorBox.Items.Add(coltoStr(Canvas.Pixels[X,Y]));
  67.        FormPaintbrush.ColorBox.Selected:=FormPaintbrush.Shape1.Brush.Color;
  68.        mDrawColor:=FormPaintbrush.Shape1.Brush.Color;
  69.        //设置CursorColor的位置
  70.        CursorColor.Left := X-2;
  71.        CursorColor.Top := Y-2;
  72.     end
  73.     //将CursorColor隐藏
  74.     else FormCanvas.CursorColor.Hide;
  75.     //如果选中文字按钮,那么显示文字输入框,
  76.     //否则隐藏文字输入框
  77.     if mType<>12 then FormTxt.Hide
  78.     else
  79.     begin
  80.        //设置字体的属性
  81.        Image1.Canvas.Font.Charset:=FormTxt.Edit1.Font.Charset;
  82.        Image1.Canvas.Font.Color:=FormTxt.Edit1.Font.Color;
  83.        Image1.Canvas.Font.Size:=FormTxt.Edit1.Font.Size;
  84.        Image1.Canvas.Font.Name:=FormTxt.Edit1.Font.Name;
  85.        Image1.Canvas.Font.Pitch:=FormTxt.Edit1.Font.Pitch;
  86.        Image1.Canvas.Font.Height:=FormTxt.Edit1.Font.Height;
  87.        Image1.Canvas.Font.Style:=FormTxt.Edit1.Font.Style;
  88.        //清空 Edit1
  89.        FormTxt.Edit1.Clear;
  90.        //设置窗口FormTxt的位置
  91.        FormTxt.Left:=X;
  92.        FormTxt.Top:=Y;
  93.        //显示窗口
  94.        FormTxt.Show;
  95.     end;
  96.   end;
  97. end;
  98. //响应image1的鼠标移动事件
  99. procedure TFormCanvas.Image1MouseMove(Sender: TObject; Shift: TShiftState;
  100.   X, Y: Integer);
  101. var
  102. Xa,Ya,Xb,Yb:real;
  103. D: real;
  104. X1,Y1,X0,Y0:Integer;
  105. begin
  106.   //判断鼠标左键是否处于下压状态
  107.   if(ssLeft in  Shift) and (mType<>0)then
  108.   begin
  109.     //设置画笔为pmNotXor模式(此模式下,在同一位置绘制两遍,会导致相互抵消)
  110.     image1.Canvas.Pen.Mode:=pmNotXor;
  111.     //设置画刷为透明模式
  112.     image1.Canvas.Brush.Style:=bsClear;
  113.     //设置画笔的线宽
  114.     image1.Canvas.Pen.Width:=mDrawWidth;
  115.     //设置画笔的颜色
  116.     image1.Canvas.Pen.Color:=mDrawColor;
  117.     //根据mDrawType绘制不同图元
  118.     if(mType=1)then
  119.     begin
  120.       //绘制上一个鼠标点的直线,以便消除该直线
  121.       image1.Canvas.MoveTo(mStartPoint.X,mStartPoint.Y);
  122.       image1.Canvas.LineTo(mMovePrePoint.X,mMovePrePoint.Y);
  123.       //绘制当前鼠标点的直线
  124.       image1.Canvas.MoveTo(mStartPoint.X,mStartPoint.Y);
  125.       image1.Canvas.LineTo(X,Y);
  126.     end
  127.     else if(mType=2)then
  128.     begin
  129.       //绘制上一个鼠标点的矩形,以便消除该矩形
  130.       image1.Canvas.Rectangle(mStartPoint.X,mStartPoint.Y,
  131.                        mMovePrePoint.X,mMovePrePoint.Y);
  132.       //绘制当前鼠标点的矩形
  133.       image1.Canvas.Rectangle(mStartPoint.X,mStartPoint.Y,
  134.                        X,Y);
  135.     end
  136.     else if(mType=3)then
  137.     begin
  138.       //绘制上一个鼠标点的椭圆,以便消除该椭圆
  139.       image1.Canvas.Ellipse(mStartPoint.X,mStartPoint.Y,
  140.                      mMovePrePoint.X,mMovePrePoint.Y);
  141.       //绘制当前的椭圆
  142.       image1.Canvas.Ellipse(mStartPoint.X,mStartPoint.Y,
  143.                      X,Y);
  144.     end
  145.     else if(mType=4)then
  146.     begin
  147.       //设置画刷颜色
  148.       image1.Canvas.Brush.color:=mDrawColor;
  149.       //绘制上一个鼠标点的椭圆,以便消除该椭圆
  150.       image1.Canvas.Ellipse(mStartPoint.X,mStartPoint.Y,
  151.                      mMovePrePoint.X,mMovePrePoint.Y);
  152.       //绘制当前的椭圆
  153.       image1.Canvas.Ellipse(mStartPoint.X,mStartPoint.Y,
  154.                      X,Y);
  155.     end
  156.     else if(mType=5)then
  157.     begin
  158.       //设置画刷颜色
  159.       image1.Canvas.Brush.color:=mDrawColor;
  160.       //绘制上一个鼠标点的矩形,以便消除该矩形
  161.       image1.Canvas.Rectangle(mStartPoint.X,mStartPoint.Y,
  162.                        mMovePrePoint.X,mMovePrePoint.Y);
  163.       //绘制当前鼠标点的矩形
  164.       image1.Canvas.Rectangle(mStartPoint.X,mStartPoint.Y,
  165.                        X,Y);
  166.     end
  167.     else if(mType=6)then
  168.     begin
  169.       //设置画笔为pmcopy模式
  170.       image1.Canvas.Pen.Mode:=pmcopy;
  171.       //绘制当前鼠标点的直线
  172.       image1.Canvas.MoveTo(mMovePrePoint.X,mMovePrePoint.Y);
  173.       image1.Canvas.LineTo(X,Y);
  174.     end
  175.     else if(mType=7)then
  176.     begin
  177.        if(mCNO mod 3=1) then
  178.        begin
  179.          //将image1的颜色设置为黑色
  180.          image1.Canvas.Brush.Color:=clblack;
  181.          image1.Canvas.FillRect(rect(x-mDrawWidth-3,y-mDrawWidth-3,x+mDrawWidth+3,y+mDrawWidth+3));
  182.        end
  183.        else if(mCNO mod 3=2) then
  184.        begin
  185.          //将image1的颜色设置为白色
  186.          image1.Canvas.Brush.Color:=clwhite;
  187.          image1.Canvas.FillRect(rect(x-mDrawWidth-3,y-mDrawWidth-3,x+mDrawWidth,y+mDrawWidth));
  188.        end
  189.        else
  190.        begin
  191.          //设置画刷颜色
  192.          image1.Canvas.Brush.color:=clwhite;
  193.          image1.Canvas.BrushCopy(rect(x-mDrawWidth,y-mDrawWidth,x+mDrawWidth,y+mDrawWidth),
  194.              imageCopy.Picture.Bitmap,rect(x-mDrawWidth,y-mDrawWidth,x+mDrawWidth,y+mDrawWidth),clWhite);
  195.        end;
  196.     end
  197.     else if(mType=8)then
  198.     begin
  199.       //绘制上一个鼠标点的箭头,以便消除该箭头
  200.       image1.Canvas.MoveTo(mStartPoint.X,mStartPoint.Y);
  201.       image1.Canvas.LineTo(mMovePrePoint.X,mMovePrePoint.Y);
  202.       X0 := mStartPoint.X;
  203.       Y0 := mStartPoint.Y;
  204.       X1 := mMovePrePoint.X;
  205.       Y1 := mMovePrePoint.Y;
  206.       D := Sqrt((Y1 - Y0) * (Y1 - Y0) + (X1 - X0) * (X1 - X0));
  207.       if D>0 then
  208.       begin
  209.         Xa := X1 + 10*((X0-X1) + (Y0-Y1)/2)/D;
  210.         Ya := Y1 + 10*((Y0-Y1) - (X0-X1)/2)/D;
  211.         Xb := X1 + 10*((X0-X1) - (Y0-Y1)/2)/D;
  212.         Yb := Y1 + 10*((Y0-Y1) + (X0-X1)/2)/D;
  213.         image1.Canvas.MoveTo(mMovePrePoint.X,mMovePrePoint.Y);
  214.         image1.Canvas.LineTo(Trunc(Xa),Trunc(Ya));
  215.         image1.Canvas.MoveTo(mMovePrePoint.X,mMovePrePoint.Y);
  216.         image1.Canvas.LineTo(Trunc(Xb), Trunc(Yb));
  217.       end;
  218.       //绘制当前鼠标点的箭头
  219.       image1.Canvas.MoveTo(mStartPoint.X,mStartPoint.Y);
  220.       image1.Canvas.LineTo(X,Y);
  221.       X0 := mStartPoint.X;
  222.       Y0 := mStartPoint.Y;
  223.       X1 := X;
  224.       Y1 := Y;
  225.       D := Sqrt((Y1 - Y0) * (Y1 - Y0) + (X1 - X0) * (X1 - X0));
  226.       if D>0 then
  227.       begin
  228.         Xa := X1 + 10*((X0-X1) + (Y0-Y1)/2)/D;
  229.         Ya := Y1 + 10*((Y0-Y1) - (X0-X1)/2)/D;
  230.         Xb := X1 + 10*((X0-X1) - (Y0-Y1)/2)/D;
  231.         Yb := Y1 + 10*((Y0-Y1) + (X0-X1)/2)/D;
  232.         image1.Canvas.MoveTo(X,Y);
  233.         image1.Canvas.LineTo(Trunc(Xa),Trunc(Ya));
  234.         image1.Canvas.MoveTo(X,Y);
  235.         image1.Canvas.LineTo(Trunc(Xb),Trunc(Yb));
  236.       end
  237.       else if(mType=10) then
  238.       begin
  239.          //设置CursorColor的位置
  240.          CursorColor.Left := X - 2;
  241.          CursorColor.Top := Y - 2;
  242.       end;
  243.     end;
  244.     //保存当前点坐标到mMovePrePoint变量中,以便下一次消除用。
  245.     mMovePrePoint.x:=x;
  246.     mMovePrePoint.y:=y;
  247.   end;
  248.   if(FormPaintbrush.ToolButtonEnlarge.Down=true)then
  249.     begin
  250.       {if(X>Image2.Left) and(Y<Image2.Height) then
  251.       begin
  252.         Image2.Hide;
  253.         sleep(100);
  254.         Image2.Top:=Image2.Height+50;
  255.         Image2.Show;
  256.       end; }
  257.       //放大鼠标所在及其周边的图片
  258.       StretchBlt(Image2.Canvas.Handle,0,0,Image2.Width,Image2.Height,
  259.       Image1.Canvas.Handle,X-20,Y-20,40,40,SRCCOPY);
  260.       //刷新
  261.       Image2.Refresh;
  262.      end;
  263. end;
  264. //响应image1的鼠标弹起事件
  265. procedure TFormCanvas.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  266.   Shift: TShiftState; X, Y: Integer);
  267. var
  268. rect:Trect;
  269. Xa, Ya, Xb, Yb: real;
  270. D: real;
  271. X1, Y1, X0, Y0: Integer;
  272. begin
  273.   //判断是否为左键下压
  274.   if(Button=mbLeft) and (mType<>0)then
  275.   begin
  276.     //保存图元的终点坐标
  277.     mEndPoint.x:=X;
  278.     mEndPoint.y:=Y;
  279.     //把画笔的绘图模式改成默认的pmCopy
  280.     image1.Canvas.Pen.Mode:=pmCopy;
  281.     //设置画刷为透明模式
  282.     image1.Canvas.Brush.Style:=bsClear;
  283.     //设置画笔的线宽
  284.     image1.Canvas.Pen.Width:=mDrawWidth;
  285.     //设置画笔的颜色
  286.     image1.Canvas.Pen.Color:=mDrawColor;
  287.     //根据mDrawType值,分别绘制不同的图元
  288.    if(mType=1)then
  289.     begin
  290.       //绘制直线
  291.       image1.Canvas.MoveTo(mStartPoint.X,mStartPoint.Y);
  292.       image1.Canvas.LineTo(mEndPoint.X,mEndPoint.Y);
  293.     end
  294.     else if (mType=2)then
  295.       //绘制矩形
  296.       image1.Canvas.Rectangle(mStartPoint.X,mStartPoint.y,
  297.                        mEndPoint.X,mEndPoint.Y)
  298.     else if (mType=3)then
  299.       //绘制椭圆
  300.       image1.Canvas.Ellipse(mStartPoint.X,mStartPoint.y,
  301.                        mEndPoint.X,mEndPoint.Y)
  302.     else if (mType=4)then
  303.     begin
  304.       //设置画刷颜色
  305.       image1.Canvas.Brush.color:=mDrawColor;
  306.       //绘制当前的椭圆
  307.       image1.Canvas.Ellipse(mStartPoint.X,mStartPoint.Y,
  308.                      X,Y);
  309.     end
  310.     else if(mType=5)then
  311.     begin
  312.       //设置画刷颜色
  313.       image1.Canvas.Brush.color:=mDrawColor;
  314.       //绘制当前鼠标点的矩形
  315.       image1.Canvas.Rectangle(mStartPoint.X,mStartPoint.Y,
  316.                        X,Y);
  317.     end
  318.     else if(mType=6)then
  319.     begin
  320.       //绘制当前鼠标点的直线
  321.       image1.Canvas.MoveTo(mMovePrePoint.X,mMovePrePoint.Y);
  322.       image1.Canvas.LineTo(X,Y);
  323.     end
  324.     else if(mType=8)then
  325.     begin
  326.       //绘制当前鼠标点的箭头
  327.       image1.Canvas.MoveTo(mStartPoint.X,mStartPoint.Y);
  328.       image1.Canvas.LineTo(X,Y);
  329.       X0 := mStartPoint.X;
  330.       Y0 := mStartPoint.Y;
  331.       X1 := X;
  332.       Y1 := Y;
  333.       D := Sqrt((Y1 - Y0) * (Y1 - Y0) + (X1 - X0) * (X1 - X0));
  334.       if D>0 then
  335.       begin
  336.         Xa := X1 + 10*((X0-X1) + (Y0-Y1)/2)/D;
  337.         Ya := Y1 + 10*((Y0-Y1) - (X0-X1)/2)/D;
  338.         Xb := X1 + 10*((X0-X1) - (Y0-Y1)/2)/D;
  339.         Yb := Y1 + 10*((Y0-Y1) + (X0-X1)/2)/D;
  340.         image1.Canvas.MoveTo(X,Y);
  341.         image1.Canvas.LineTo(Trunc(Xa),Trunc(Ya));
  342.         image1.Canvas.MoveTo(X,Y);
  343.         image1.Canvas.LineTo(Trunc(Xb), Trunc(Yb));
  344.       end;
  345.     end
  346.     else if(mType=11)then
  347.     begin
  348.       //设置画笔的线宽
  349.       image1.Canvas.Pen.Width:=4;
  350.       image1.Canvas.Rectangle(X+25,Y+20,X-25,Y-20);
  351.       image1.Canvas.Rectangle(X+20,Y+15,X-20,Y-15);
  352.       image1.Canvas.MoveTo(X+15,Y+20);
  353.       image1.Canvas.LineTo(X+15,Y+26);
  354.       image1.Canvas.MoveTo(X-15,Y+20);
  355.       image1.Canvas.LineTo(X-15,Y+26);
  356.       image1.Canvas.Rectangle(X-30,Y+26,X+30,Y+35);
  357.       //设置画笔的线宽
  358.       image1.Canvas.Pen.Width:=mDrawWidth;
  359.     end
  360.     else if(mType=14)then
  361.     begin
  362.       //设置画笔的线宽
  363.       image1.Canvas.Pen.Width:=4;
  364.       image1.Canvas.MoveTo(X-40,Y);
  365.       image1.Canvas.LineTo(X,Y-30);
  366.       image1.Canvas.MoveTo(X,Y-30);
  367.       image1.Canvas.LineTo(X+40,Y);
  368.       image1.Canvas.MoveTo(X+40,Y);
  369.       image1.Canvas.LineTo(X,Y+30);
  370.       image1.Canvas.MoveTo(X,Y+30);
  371.       image1.Canvas.LineTo(X-40,Y);
  372.       image1.Canvas.MoveTo(X+40,Y+20);
  373.       image1.Canvas.LineTo(X,Y+50);
  374.       image1.Canvas.MoveTo(X,Y+50);
  375.       image1.Canvas.LineTo(X-40,Y+20);
  376.       image1.Canvas.MoveTo(X+40,Y+20);
  377.       image1.Canvas.LineTo(X+40,Y);
  378.       image1.Canvas.MoveTo(X-40,Y);
  379.       image1.Canvas.LineTo(X-40,Y+20);
  380.       image1.Canvas.MoveTo(X,Y+30);
  381.       image1.Canvas.LineTo(X,Y+50);
  382.       image1.Canvas.MoveTo(X-15,Y+11);
  383.       image1.Canvas.LineTo(X,Y+22);
  384.       image1.Canvas.MoveTo(X-10,Y+7);
  385.       image1.Canvas.LineTo(X+4,Y+18);
  386.       image1.Canvas.MoveTo(X-10,Y+7);
  387.       image1.Canvas.LineTo(X-15,Y+11);
  388.       image1.Canvas.MoveTo(X-3,Y+24);
  389.       image1.Canvas.LineTo(X,Y+22);
  390.       image1.Canvas.MoveTo(X+7,Y+16);
  391.       image1.Canvas.LineTo(X+4,Y+18);
  392.       image1.Canvas.MoveTo(X+7,Y+16);
  393.       image1.Canvas.LineTo(X+7,Y+26);
  394.       image1.Canvas.MoveTo(X-3,Y+24);
  395.       image1.Canvas.LineTo(X+7,Y+26);
  396.       image1.Canvas.MoveTo(X+15,Y-11);
  397.       image1.Canvas.LineTo(X,Y-22);
  398.       image1.Canvas.MoveTo(X+10,Y-7);
  399.       image1.Canvas.LineTo(X-4,Y-18);
  400.       image1.Canvas.MoveTo(X+10,Y-7);
  401.       image1.Canvas.LineTo(X+15,Y-11);
  402.       image1.Canvas.MoveTo(X+3,Y-24);
  403.       image1.Canvas.LineTo(X,Y-22);
  404.       image1.Canvas.MoveTo(X-7,Y-16);
  405.       image1.Canvas.LineTo(X-4,Y-18);
  406.       image1.Canvas.MoveTo(X-7,Y-16);
  407.       image1.Canvas.LineTo(X-7,Y-26);
  408.       image1.Canvas.MoveTo(X+3,Y-24);
  409.       image1.Canvas.LineTo(X-7,Y-26);
  410.       image1.Canvas.MoveTo(X+8,Y-5);
  411.       image1.Canvas.LineTo(X+23,Y+7);
  412.       image1.Canvas.MoveTo(X+3,Y-1);
  413.       image1.Canvas.LineTo(X+18,Y+11);
  414.       image1.Canvas.MoveTo(X+8,Y-5);
  415.       image1.Canvas.LineTo(X+3,Y-1);
  416.       image1.Canvas.MoveTo(X+23,Y+7);
  417.       image1.Canvas.LineTo(X+25,Y+3);
  418.       image1.Canvas.MoveTo(X+18,Y+11);
  419.       image1.Canvas.LineTo(X+14,Y+13);
  420.       image1.Canvas.MoveTo(X+25,Y+3);
  421.       image1.Canvas.LineTo(X+25,Y+12);
  422.       image1.Canvas.MoveTo(X+14,Y+13);
  423.       image1.Canvas.LineTo(X+25,Y+12);
  424.       image1.Canvas.MoveTo(X-8,Y+5);
  425.       image1.Canvas.LineTo(X-23,Y-7);
  426.       image1.Canvas.MoveTo(X-3,Y+1);
  427.       image1.Canvas.LineTo(X-18,Y-11);
  428.       image1.Canvas.MoveTo(X-8,Y+5);
  429.       image1.Canvas.LineTo(X-3,Y+1);
  430.       image1.Canvas.MoveTo(X-23,Y-7);
  431.       image1.Canvas.LineTo(X-25,Y-3);
  432.       image1.Canvas.MoveTo(X-18,Y-11);
  433.       image1.Canvas.LineTo(X-14,Y-13);
  434.       image1.Canvas.MoveTo(X-25,Y-3);
  435.       image1.Canvas.LineTo(X-25,Y-12);
  436.       image1.Canvas.MoveTo(X-14,Y-13);
  437.       image1.Canvas.LineTo(X-25,Y-12);
  438.       //设置画笔的线宽
  439.       image1.Canvas.Pen.Width:=mDrawWidth;
  440.     end
  441.      else if(mType=13)then
  442.     begin
  443.       //设置画笔的线宽
  444.       image1.Canvas.Pen.Width:=4;
  445.       image1.Canvas.Ellipse(X-100,Y-50,X,Y);
  446.       image1.Canvas.Arc(X-100,Y-30,X,Y+20,X-100,Y-5,X,Y-5);
  447.       image1.Canvas.MoveTo(X-100,Y-25);
  448.       image1.Canvas.LineTo(X-100,Y-5);
  449.       image1.Canvas.MoveTo(X,Y-25);
  450.       image1.Canvas.LineTo(X,Y-5);
  451.       image1.Canvas.MoveTo(X-55,Y-20);
  452.       image1.Canvas.LineTo(X-75,Y-10);
  453.       image1.Canvas.MoveTo(X-60,Y-23);
  454.       image1.Canvas.LineTo(X-80,Y-13);
  455.       image1.Canvas.MoveTo(X-60,Y-23);
  456.       image1.Canvas.LineTo(X-55,Y-20);
  457.       image1.Canvas.MoveTo(X-70,Y-9);
  458.       image1.Canvas.LineTo(X-75,Y-10);
  459.       image1.Canvas.MoveTo(X-83,Y-15);
  460.       image1.Canvas.LineTo(X-80,Y-13);
  461.       image1.Canvas.MoveTo(X-84,Y-10);
  462.       image1.Canvas.LineTo(X-70,Y-9);
  463.       image1.Canvas.MoveTo(X-84,Y-10);
  464.       image1.Canvas.LineTo(X-83,Y-15);
  465.       image1.Canvas.MoveTo(X-45,Y-30);
  466.       image1.Canvas.LineTo(X-25,Y-40);
  467.       image1.Canvas.MoveTo(X-40,Y-27);
  468.       image1.Canvas.LineTo(X-20,Y-37);
  469.       image1.Canvas.MoveTo(X-40,Y-27);
  470.       image1.Canvas.LineTo(X-45,Y-30);
  471.       image1.Canvas.MoveTo(X-30,Y-41);
  472.       image1.Canvas.LineTo(X-25,Y-40);
  473.       image1.Canvas.MoveTo(X-17,Y-35);
  474.       image1.Canvas.LineTo(X-20,Y-37);
  475.       image1.Canvas.MoveTo(X-16,Y-40);
  476.       image1.Canvas.LineTo(X-30,Y-41);
  477.       image1.Canvas.MoveTo(X-16,Y-40);
  478.       image1.Canvas.LineTo(X-17,Y-35);
  479.       image1.Canvas.MoveTo(X-18,Y-10);
  480.       image1.Canvas.LineTo(X-38,Y-20);
  481.       image1.Canvas.MoveTo(X-23,Y-7);
  482.       image1.Canvas.LineTo(X-43,Y-17);
  483.       image1.Canvas.MoveTo(X-23,Y-7);
  484.       image1.Canvas.LineTo(X-18,Y-10);
  485.       image1.Canvas.MoveTo(X-35,Y-22);
  486.       image1.Canvas.LineTo(X-38,Y-20);
  487.       image1.Canvas.MoveTo(X-46,Y-15);
  488.       image1.Canvas.LineTo(X-43,Y-17);
  489.       image1.Canvas.MoveTo(X-35,Y-22);
  490.       image1.Canvas.LineTo(X-46,Y-23);
  491.       image1.Canvas.MoveTo(X-46,Y-15);
  492.       image1.Canvas.LineTo(X-46,Y-23);
  493.       image1.Canvas.MoveTo(X-82,Y-40);
  494.       image1.Canvas.LineTo(X-62,Y-30);
  495.       image1.Canvas.MoveTo(X-77,Y-43);
  496.       image1.Canvas.LineTo(X-57,Y-33);
  497.       image1.Canvas.MoveTo(X-77,Y-43);
  498.       image1.Canvas.LineTo(X-82,Y-40);
  499.       image1.Canvas.MoveTo(X-65,Y-28);
  500.       image1.Canvas.LineTo(X-62,Y-30);
  501.       image1.Canvas.MoveTo(X-54,Y-35);
  502.       image1.Canvas.LineTo(X-57,Y-33);
  503.       image1.Canvas.MoveTo(X-65,Y-28);
  504.       image1.Canvas.LineTo(X-54,Y-27);
  505.       image1.Canvas.MoveTo(X-54,Y-35);
  506.       image1.Canvas.LineTo(X-54,Y-27);
  507.       //设置画笔的线宽
  508.       image1.Canvas.Pen.Width:=mDrawWidth;
  509.     end
  510.     else if(mType=15)then
  511.     begin
  512.       //设置画笔的线宽
  513.       image1.Canvas.Pen.Width:=4;
  514.       image1.Canvas.MoveTo(X-40,Y-15);
  515.       image1.Canvas.LineTo(X+40,Y-15);
  516.       image1.Canvas.MoveTo(X+40,Y-15);
  517.       image1.Canvas.LineTo(X+40,Y+15);
  518.       image1.Canvas.MoveTo(X-40,Y+15);
  519.       image1.Canvas.LineTo(X+40,Y+15);
  520.       image1.Canvas.MoveTo(X-40,Y-15);
  521.       image1.Canvas.LineTo(X-40,Y-9);
  522.       image1.Canvas.MoveTo(X-40,Y+9);
  523.       image1.Canvas.LineTo(X-40,Y+15);
  524.       image1.Canvas.Rectangle(X-45,Y-9,X-27,Y+9);
  525.       image1.Canvas.Rectangle(X-35,Y+15,X+35,Y+21);
  526.       image1.Canvas.pen.Width:=1;
  527.       image1.Canvas.pen.Color:=clblack;
  528.       image1.Canvas.Brush.color:=clgreen;
  529.       image1.Canvas.Rectangle(X+30,Y-10,X+38,Y);
  530.       image1.Canvas.Brush.color:=clred;
  531.       image1.Canvas.Rectangle(X+20,Y-10,X+30,Y);
  532.       //设置画笔的线宽
  533.       image1.Canvas.Pen.Width:=mDrawWidth;
  534.     end
  535.     else if(mType=16)then
  536.     begin
  537.       //设置画笔的线宽
  538.       image1.Canvas.Pen.Width:=4;
  539.       image1.Canvas.Rectangle(X-40,Y-15,X+40,Y+15);
  540.       image1.Canvas.Rectangle(X-37,Y-12,X+37,Y);
  541.       image1.Canvas.pen.Width:=1;
  542.       image1.Canvas.pen.Color:=clblack;
  543.       image1.Canvas.Brush.color:=cl3DDkShadow;
  544.       image1.Canvas.Rectangle(X+25,Y+5,X+35,Y+9);
  545.       image1.Canvas.Brush.color:=clgreen;
  546.       image1.Canvas.Ellipse(X+15,Y+2,X+20,Y+12);
  547.       //设置画笔的线宽
  548.       image1.Canvas.Pen.Width:=mDrawWidth;
  549.     end
  550.     else if(mType=17)then
  551.     begin
  552.       //设置画笔的线宽
  553.       image1.Canvas.Pen.Width:=4;
  554.       image1.Canvas.Rectangle(X-20,Y-45,X+20,Y+45);
  555.       image1.Canvas.Rectangle(X-15,Y-35,X+15,Y-28);
  556.       image1.Canvas.Rectangle(X-15,Y-23,X+15,Y-15);
  557.       image1.Canvas.RoundRect(X-10,Y-20,X+10,Y-18,4,1);
  558.       //image1.Canvas.Rectangle(X-10,Y-20,X+10,Y-18);
  559.       image1.Canvas.pen.Width:=1;
  560.       image1.Canvas.pen.Color:=clblack;
  561.       image1.Canvas.Brush.color:=clgreen;
  562.       image1.Canvas.Ellipse(X+3,Y+3,X-3,Y-3);
  563.       image1.Canvas.MoveTo(X-15,Y+20);
  564.       image1.Canvas.LineTo(X+14,Y+20);
  565.       image1.Canvas.MoveTo(X-15,Y+27);
  566.       image1.Canvas.LineTo(X+14,Y+27);
  567.       image1.Canvas.MoveTo(X-15,Y+34);
  568.       image1.Canvas.LineTo(X+14,Y+34);
  569.       //设置画笔的线宽
  570.       image1.Canvas.Pen.Width:=mDrawWidth;
  571.     end
  572.     else if(mType=18)then
  573.     begin
  574.       //设置画笔的线宽
  575.       image1.Canvas.Pen.Width:=4;
  576.       image1.Canvas.Ellipse(X-70,Y-50,X,Y);
  577.       image1.Canvas.Arc(X-70,Y-30,X,Y+20,X-100,Y-5,X,Y-5);
  578.       image1.Canvas.MoveTo(X-70,Y-25);
  579.       image1.Canvas.LineTo(X-70,Y-5);
  580.       image1.Canvas.MoveTo(X,Y-25);
  581.       image1.Canvas.LineTo(X,Y-5);
  582.       //设置画笔的线宽
  583.       image1.Canvas.Pen.Width:=mDrawWidth;
  584.     end
  585.     else if(mType=19)then
  586.     begin
  587.       //设置画笔的线宽
  588.       image1.Canvas.Pen.Width:=4;
  589.       image1.Canvas.MoveTo(X-40,Y);
  590.       image1.Canvas.LineTo(X,Y-30);
  591.       image1.Canvas.MoveTo(X,Y-30);
  592.       image1.Canvas.LineTo(X+40,Y);
  593.       image1.Canvas.MoveTo(X+40,Y);
  594.       image1.Canvas.LineTo(X,Y+30);
  595.       image1.Canvas.MoveTo(X,Y+30);
  596.       image1.Canvas.LineTo(X-40,Y);
  597.       image1.Canvas.MoveTo(X+40,Y+20);
  598.       image1.Canvas.LineTo(X,Y+50);
  599.       image1.Canvas.MoveTo(X,Y+50);
  600.       image1.Canvas.LineTo(X-40,Y+20);
  601.       image1.Canvas.MoveTo(X+40,Y+20);
  602.       image1.Canvas.LineTo(X+40,Y);
  603.       image1.Canvas.MoveTo(X-40,Y);
  604.       image1.Canvas.LineTo(X-40,Y+20);
  605.       image1.Canvas.MoveTo(X,Y+30);
  606.       image1.Canvas.LineTo(X,Y+50);
  607.       image1.Canvas.MoveTo(X-20,Y-8);
  608.       image1.Canvas.LineTo(X,Y+7);
  609.       image1.Canvas.MoveTo(X-12,Y-14);
  610.       image1.Canvas.LineTo(X+8,Y+1);
  611.       image1.Canvas.MoveTo(X-12,Y-14);
  612.       image1.Canvas.LineTo(X-20,Y-8);
  613.       image1.Canvas.MoveTo(X-5,Y+10);
  614.       image1.Canvas.LineTo(X,Y+7);
  615.       image1.Canvas.MoveTo(X+13,Y-2);
  616.       image1.Canvas.LineTo(X+8,Y+1);
  617.       image1.Canvas.MoveTo(X-5,Y+10);
  618.       image1.Canvas.LineTo(X+14,Y+14 );
  619.       image1.Canvas.MoveTo(X+13,Y-2);
  620.       image1.Canvas.LineTo(X+14,Y+14);
  621.       //设置画笔的线宽
  622.       image1.Canvas.Pen.Width:=mDrawWidth;
  623.     end
  624.     else if(mType=20)then
  625.     begin
  626.       //设置画笔的线宽
  627.       image1.Canvas.Pen.Width:=4;
  628.       image1.Canvas.MoveTo(X+35,Y-30);
  629.       image1.Canvas.LineTo(X+35,Y+30);
  630.       image1.Canvas.MoveTo(X+35,Y+30);
  631.       image1.Canvas.LineTo(X-35,Y+30);
  632.       image1.Canvas.MoveTo(X-35,Y+30);
  633.       image1.Canvas.LineTo(X-35,Y-30);
  634.       image1.Canvas.Arc(X+35,Y+10,X-35,Y-90,X-35,Y-30,X+35,Y-30);
  635.       image1.Canvas.MoveTo(X+55,Y+15);
  636.       image1.Canvas.LineTo(X+35,Y+30);
  637.       image1.Canvas.MoveTo(X+55,Y+15);
  638.       image1.Canvas.LineTo(X+55,Y-45);
  639.       image1.Canvas.MoveTo(X+35,Y-30);
  640.       image1.Canvas.LineTo(X+55,Y-45);
  641.       image1.Canvas.MoveTo(X-35,Y-30);
  642.       image1.Canvas.LineTo(X-15,Y-45);
  643.       image1.Canvas.Arc(X+55,Y-5,X-15,Y-115,X-15,Y-45,X+25,Y-6);
  644.       //设置画笔的线宽
  645.       image1.Canvas.Pen.Width:=mDrawWidth;
  646.     end;
  647.     //保存图象
  648.     rect.Left:=0;
  649.     rect.Top:=0;
  650.     rect.Right:=Image1.Width;
  651.     rect.Bottom:=Image1.Height;
  652.     Bitmap.Width:=Image1.Width;
  653.     Bitmap.Height:=Image1.Height;
  654.     Bitmap.Canvas.CopyRect(rect,Image1.Canvas,rect);
  655.     //设置修改标志
  656.     mModifyFlag:=true;
  657.   end;
  658. end;
  659. procedure TFormCanvas.FormShow(Sender: TObject);
  660. begin
  661.    //初始化当前正在绘制的图元类型
  662.    mType:=0;
  663.    //初始化当前正在绘制的图元线宽
  664.    mDrawWidth:=StrToInt(FormPaintbrush.ComboBoxWidth.text);
  665.    //初始化当前正在绘制的图元颜色($000000代表黑色,$FFFFFF代表白色,$0000FF代表红色)
  666.    FormPaintbrush.Shape1.Brush.Color:=FormPaintbrush.ColorBox.Selected;
  667.    mDrawColor:=FormPaintbrush.Shape1.Brush.Color;
  668.    //创建Bitmap,并设置其宽度和高度
  669.    Bitmap:=TBitmap.Create;
  670.    Bitmap.Width:=Image1.Width;
  671.    Bitmap.Height:=Image1.Height;
  672.    //初始化工具条的down状态(即是否下压)
  673.    FormPaintbrush.ToolButtonLine.Down:=false;
  674.    FormPaintbrush.ToolButtonRectangle.Down:=false;
  675.    FormPaintbrush.ToolButtonEllipse.Down:=false;
  676.    //初始化修改标志
  677.    mModifyFlag:=false;
  678.    //将imagecopy隐藏
  679.    imagecopy.Hide;
  680.    //将CursorColor隐藏
  681.    CursorColor.Hide;
  682. end;
  683. end.