UnitFormCanvas.pas
上传用户:conquerdj
上传日期:2022-07-08
资源大小:417k
文件大小:23k
- unit UnitFormCanvas;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ExtCtrls,StdCtrls;
- type
- TFormCanvas = class(TForm)
- Image1: TImage;
- Image2: TImage;
- CursorColor: TShape;
- Imagecopy: TImage;
- procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure FormShow(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- FormCanvas: TFormCanvas;
- //图元的起点数组
- mStartPoint :TPoint;
- //图元的终点数组
- mEndPoint :TPoint;
- //鼠标移动过程中前一个点的坐标
- mMovePrePoint: TPoint;
- //用于保存图象或向Image1拷贝图象
- Bitmap:Tbitmap;
- implementation
- uses UnitPaintbrush,UnitTxt;
- {$R *.dfm}
- //响应image1的鼠标下压事件
- procedure TFormCanvas.Image1MouseDown(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- begin
- //判断是否为右键下压
- if(Button=mbRight)then
- begin
- if(FormPaintBrush.Visible=true)then
- FormPaintBrush.Visible:=false
- else
- FormPaintBrush.Visible:=true;
- end;
- //判断是否为左键下压
- if(Button=mbLeft) and (mType<>0)then
- begin
- //保存图元的起点坐标
- mStartPoint.x:=X;
- mStartPoint.y:=Y;
- //保存当前点坐标到mMovePrePoint变量中,以便鼠标移动时第一次消除用。
- mMovePrePoint.x:=x;
- mMovePrePoint.y:=y;
- //取色
- if(mType=10) then
- begin
- //将CursorColor显示出来
- FormCanvas.CursorColor.Show;
- //设置Shape组件的颜色
- FormPaintbrush.Shape1.Brush.Color:=Canvas.Pixels[X,Y];
- //取出颜色在颜色框里显示出来
- //FormPaintbrush.ColorBox.Items.Add(coltoStr(Canvas.Pixels[X,Y]));
- FormPaintbrush.ColorBox.Selected:=FormPaintbrush.Shape1.Brush.Color;
- mDrawColor:=FormPaintbrush.Shape1.Brush.Color;
- //设置CursorColor的位置
- CursorColor.Left := X-2;
- CursorColor.Top := Y-2;
- end
- //将CursorColor隐藏
- else FormCanvas.CursorColor.Hide;
- //如果选中文字按钮,那么显示文字输入框,
- //否则隐藏文字输入框
- if mType<>12 then FormTxt.Hide
- else
- begin
- //设置字体的属性
- Image1.Canvas.Font.Charset:=FormTxt.Edit1.Font.Charset;
- Image1.Canvas.Font.Color:=FormTxt.Edit1.Font.Color;
- Image1.Canvas.Font.Size:=FormTxt.Edit1.Font.Size;
- Image1.Canvas.Font.Name:=FormTxt.Edit1.Font.Name;
- Image1.Canvas.Font.Pitch:=FormTxt.Edit1.Font.Pitch;
- Image1.Canvas.Font.Height:=FormTxt.Edit1.Font.Height;
- Image1.Canvas.Font.Style:=FormTxt.Edit1.Font.Style;
- //清空 Edit1
- FormTxt.Edit1.Clear;
- //设置窗口FormTxt的位置
- FormTxt.Left:=X;
- FormTxt.Top:=Y;
- //显示窗口
- FormTxt.Show;
- end;
- end;
- end;
- //响应image1的鼠标移动事件
- procedure TFormCanvas.Image1MouseMove(Sender: TObject; Shift: TShiftState;
- X, Y: Integer);
- var
- Xa,Ya,Xb,Yb:real;
- D: real;
- X1,Y1,X0,Y0:Integer;
- begin
- //判断鼠标左键是否处于下压状态
- if(ssLeft in Shift) and (mType<>0)then
- begin
- //设置画笔为pmNotXor模式(此模式下,在同一位置绘制两遍,会导致相互抵消)
- image1.Canvas.Pen.Mode:=pmNotXor;
- //设置画刷为透明模式
- image1.Canvas.Brush.Style:=bsClear;
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=mDrawWidth;
- //设置画笔的颜色
- image1.Canvas.Pen.Color:=mDrawColor;
- //根据mDrawType绘制不同图元
- if(mType=1)then
- begin
- //绘制上一个鼠标点的直线,以便消除该直线
- image1.Canvas.MoveTo(mStartPoint.X,mStartPoint.Y);
- image1.Canvas.LineTo(mMovePrePoint.X,mMovePrePoint.Y);
- //绘制当前鼠标点的直线
- image1.Canvas.MoveTo(mStartPoint.X,mStartPoint.Y);
- image1.Canvas.LineTo(X,Y);
- end
- else if(mType=2)then
- begin
- //绘制上一个鼠标点的矩形,以便消除该矩形
- image1.Canvas.Rectangle(mStartPoint.X,mStartPoint.Y,
- mMovePrePoint.X,mMovePrePoint.Y);
- //绘制当前鼠标点的矩形
- image1.Canvas.Rectangle(mStartPoint.X,mStartPoint.Y,
- X,Y);
- end
- else if(mType=3)then
- begin
- //绘制上一个鼠标点的椭圆,以便消除该椭圆
- image1.Canvas.Ellipse(mStartPoint.X,mStartPoint.Y,
- mMovePrePoint.X,mMovePrePoint.Y);
- //绘制当前的椭圆
- image1.Canvas.Ellipse(mStartPoint.X,mStartPoint.Y,
- X,Y);
- end
- else if(mType=4)then
- begin
- //设置画刷颜色
- image1.Canvas.Brush.color:=mDrawColor;
- //绘制上一个鼠标点的椭圆,以便消除该椭圆
- image1.Canvas.Ellipse(mStartPoint.X,mStartPoint.Y,
- mMovePrePoint.X,mMovePrePoint.Y);
- //绘制当前的椭圆
- image1.Canvas.Ellipse(mStartPoint.X,mStartPoint.Y,
- X,Y);
- end
- else if(mType=5)then
- begin
- //设置画刷颜色
- image1.Canvas.Brush.color:=mDrawColor;
- //绘制上一个鼠标点的矩形,以便消除该矩形
- image1.Canvas.Rectangle(mStartPoint.X,mStartPoint.Y,
- mMovePrePoint.X,mMovePrePoint.Y);
- //绘制当前鼠标点的矩形
- image1.Canvas.Rectangle(mStartPoint.X,mStartPoint.Y,
- X,Y);
- end
- else if(mType=6)then
- begin
- //设置画笔为pmcopy模式
- image1.Canvas.Pen.Mode:=pmcopy;
- //绘制当前鼠标点的直线
- image1.Canvas.MoveTo(mMovePrePoint.X,mMovePrePoint.Y);
- image1.Canvas.LineTo(X,Y);
- end
- else if(mType=7)then
- begin
- if(mCNO mod 3=1) then
- begin
- //将image1的颜色设置为黑色
- image1.Canvas.Brush.Color:=clblack;
- image1.Canvas.FillRect(rect(x-mDrawWidth-3,y-mDrawWidth-3,x+mDrawWidth+3,y+mDrawWidth+3));
- end
- else if(mCNO mod 3=2) then
- begin
- //将image1的颜色设置为白色
- image1.Canvas.Brush.Color:=clwhite;
- image1.Canvas.FillRect(rect(x-mDrawWidth-3,y-mDrawWidth-3,x+mDrawWidth,y+mDrawWidth));
- end
- else
- begin
- //设置画刷颜色
- image1.Canvas.Brush.color:=clwhite;
- image1.Canvas.BrushCopy(rect(x-mDrawWidth,y-mDrawWidth,x+mDrawWidth,y+mDrawWidth),
- imageCopy.Picture.Bitmap,rect(x-mDrawWidth,y-mDrawWidth,x+mDrawWidth,y+mDrawWidth),clWhite);
- end;
- end
- else if(mType=8)then
- begin
- //绘制上一个鼠标点的箭头,以便消除该箭头
- image1.Canvas.MoveTo(mStartPoint.X,mStartPoint.Y);
- image1.Canvas.LineTo(mMovePrePoint.X,mMovePrePoint.Y);
- X0 := mStartPoint.X;
- Y0 := mStartPoint.Y;
- X1 := mMovePrePoint.X;
- Y1 := mMovePrePoint.Y;
- D := Sqrt((Y1 - Y0) * (Y1 - Y0) + (X1 - X0) * (X1 - X0));
- if D>0 then
- begin
- Xa := X1 + 10*((X0-X1) + (Y0-Y1)/2)/D;
- Ya := Y1 + 10*((Y0-Y1) - (X0-X1)/2)/D;
- Xb := X1 + 10*((X0-X1) - (Y0-Y1)/2)/D;
- Yb := Y1 + 10*((Y0-Y1) + (X0-X1)/2)/D;
- image1.Canvas.MoveTo(mMovePrePoint.X,mMovePrePoint.Y);
- image1.Canvas.LineTo(Trunc(Xa),Trunc(Ya));
- image1.Canvas.MoveTo(mMovePrePoint.X,mMovePrePoint.Y);
- image1.Canvas.LineTo(Trunc(Xb), Trunc(Yb));
- end;
- //绘制当前鼠标点的箭头
- image1.Canvas.MoveTo(mStartPoint.X,mStartPoint.Y);
- image1.Canvas.LineTo(X,Y);
- X0 := mStartPoint.X;
- Y0 := mStartPoint.Y;
- X1 := X;
- Y1 := Y;
- D := Sqrt((Y1 - Y0) * (Y1 - Y0) + (X1 - X0) * (X1 - X0));
- if D>0 then
- begin
- Xa := X1 + 10*((X0-X1) + (Y0-Y1)/2)/D;
- Ya := Y1 + 10*((Y0-Y1) - (X0-X1)/2)/D;
- Xb := X1 + 10*((X0-X1) - (Y0-Y1)/2)/D;
- Yb := Y1 + 10*((Y0-Y1) + (X0-X1)/2)/D;
- image1.Canvas.MoveTo(X,Y);
- image1.Canvas.LineTo(Trunc(Xa),Trunc(Ya));
- image1.Canvas.MoveTo(X,Y);
- image1.Canvas.LineTo(Trunc(Xb),Trunc(Yb));
- end
- else if(mType=10) then
- begin
- //设置CursorColor的位置
- CursorColor.Left := X - 2;
- CursorColor.Top := Y - 2;
- end;
- end;
- //保存当前点坐标到mMovePrePoint变量中,以便下一次消除用。
- mMovePrePoint.x:=x;
- mMovePrePoint.y:=y;
- end;
- if(FormPaintbrush.ToolButtonEnlarge.Down=true)then
- begin
- {if(X>Image2.Left) and(Y<Image2.Height) then
- begin
- Image2.Hide;
- sleep(100);
- Image2.Top:=Image2.Height+50;
- Image2.Show;
- end; }
- //放大鼠标所在及其周边的图片
- StretchBlt(Image2.Canvas.Handle,0,0,Image2.Width,Image2.Height,
- Image1.Canvas.Handle,X-20,Y-20,40,40,SRCCOPY);
- //刷新
- Image2.Refresh;
- end;
- end;
- //响应image1的鼠标弹起事件
- procedure TFormCanvas.Image1MouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- var
- rect:Trect;
- Xa, Ya, Xb, Yb: real;
- D: real;
- X1, Y1, X0, Y0: Integer;
- begin
- //判断是否为左键下压
- if(Button=mbLeft) and (mType<>0)then
- begin
- //保存图元的终点坐标
- mEndPoint.x:=X;
- mEndPoint.y:=Y;
- //把画笔的绘图模式改成默认的pmCopy
- image1.Canvas.Pen.Mode:=pmCopy;
- //设置画刷为透明模式
- image1.Canvas.Brush.Style:=bsClear;
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=mDrawWidth;
- //设置画笔的颜色
- image1.Canvas.Pen.Color:=mDrawColor;
- //根据mDrawType值,分别绘制不同的图元
- if(mType=1)then
- begin
- //绘制直线
- image1.Canvas.MoveTo(mStartPoint.X,mStartPoint.Y);
- image1.Canvas.LineTo(mEndPoint.X,mEndPoint.Y);
- end
- else if (mType=2)then
- //绘制矩形
- image1.Canvas.Rectangle(mStartPoint.X,mStartPoint.y,
- mEndPoint.X,mEndPoint.Y)
- else if (mType=3)then
- //绘制椭圆
- image1.Canvas.Ellipse(mStartPoint.X,mStartPoint.y,
- mEndPoint.X,mEndPoint.Y)
- else if (mType=4)then
- begin
- //设置画刷颜色
- image1.Canvas.Brush.color:=mDrawColor;
- //绘制当前的椭圆
- image1.Canvas.Ellipse(mStartPoint.X,mStartPoint.Y,
- X,Y);
- end
- else if(mType=5)then
- begin
- //设置画刷颜色
- image1.Canvas.Brush.color:=mDrawColor;
- //绘制当前鼠标点的矩形
- image1.Canvas.Rectangle(mStartPoint.X,mStartPoint.Y,
- X,Y);
- end
- else if(mType=6)then
- begin
- //绘制当前鼠标点的直线
- image1.Canvas.MoveTo(mMovePrePoint.X,mMovePrePoint.Y);
- image1.Canvas.LineTo(X,Y);
- end
- else if(mType=8)then
- begin
- //绘制当前鼠标点的箭头
- image1.Canvas.MoveTo(mStartPoint.X,mStartPoint.Y);
- image1.Canvas.LineTo(X,Y);
- X0 := mStartPoint.X;
- Y0 := mStartPoint.Y;
- X1 := X;
- Y1 := Y;
- D := Sqrt((Y1 - Y0) * (Y1 - Y0) + (X1 - X0) * (X1 - X0));
- if D>0 then
- begin
- Xa := X1 + 10*((X0-X1) + (Y0-Y1)/2)/D;
- Ya := Y1 + 10*((Y0-Y1) - (X0-X1)/2)/D;
- Xb := X1 + 10*((X0-X1) - (Y0-Y1)/2)/D;
- Yb := Y1 + 10*((Y0-Y1) + (X0-X1)/2)/D;
- image1.Canvas.MoveTo(X,Y);
- image1.Canvas.LineTo(Trunc(Xa),Trunc(Ya));
- image1.Canvas.MoveTo(X,Y);
- image1.Canvas.LineTo(Trunc(Xb), Trunc(Yb));
- end;
- end
- else if(mType=11)then
- begin
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=4;
- image1.Canvas.Rectangle(X+25,Y+20,X-25,Y-20);
- image1.Canvas.Rectangle(X+20,Y+15,X-20,Y-15);
- image1.Canvas.MoveTo(X+15,Y+20);
- image1.Canvas.LineTo(X+15,Y+26);
- image1.Canvas.MoveTo(X-15,Y+20);
- image1.Canvas.LineTo(X-15,Y+26);
- image1.Canvas.Rectangle(X-30,Y+26,X+30,Y+35);
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=mDrawWidth;
- end
- else if(mType=14)then
- begin
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=4;
- image1.Canvas.MoveTo(X-40,Y);
- image1.Canvas.LineTo(X,Y-30);
- image1.Canvas.MoveTo(X,Y-30);
- image1.Canvas.LineTo(X+40,Y);
- image1.Canvas.MoveTo(X+40,Y);
- image1.Canvas.LineTo(X,Y+30);
- image1.Canvas.MoveTo(X,Y+30);
- image1.Canvas.LineTo(X-40,Y);
- image1.Canvas.MoveTo(X+40,Y+20);
- image1.Canvas.LineTo(X,Y+50);
- image1.Canvas.MoveTo(X,Y+50);
- image1.Canvas.LineTo(X-40,Y+20);
- image1.Canvas.MoveTo(X+40,Y+20);
- image1.Canvas.LineTo(X+40,Y);
- image1.Canvas.MoveTo(X-40,Y);
- image1.Canvas.LineTo(X-40,Y+20);
- image1.Canvas.MoveTo(X,Y+30);
- image1.Canvas.LineTo(X,Y+50);
- image1.Canvas.MoveTo(X-15,Y+11);
- image1.Canvas.LineTo(X,Y+22);
- image1.Canvas.MoveTo(X-10,Y+7);
- image1.Canvas.LineTo(X+4,Y+18);
- image1.Canvas.MoveTo(X-10,Y+7);
- image1.Canvas.LineTo(X-15,Y+11);
- image1.Canvas.MoveTo(X-3,Y+24);
- image1.Canvas.LineTo(X,Y+22);
- image1.Canvas.MoveTo(X+7,Y+16);
- image1.Canvas.LineTo(X+4,Y+18);
- image1.Canvas.MoveTo(X+7,Y+16);
- image1.Canvas.LineTo(X+7,Y+26);
- image1.Canvas.MoveTo(X-3,Y+24);
- image1.Canvas.LineTo(X+7,Y+26);
- image1.Canvas.MoveTo(X+15,Y-11);
- image1.Canvas.LineTo(X,Y-22);
- image1.Canvas.MoveTo(X+10,Y-7);
- image1.Canvas.LineTo(X-4,Y-18);
- image1.Canvas.MoveTo(X+10,Y-7);
- image1.Canvas.LineTo(X+15,Y-11);
- image1.Canvas.MoveTo(X+3,Y-24);
- image1.Canvas.LineTo(X,Y-22);
- image1.Canvas.MoveTo(X-7,Y-16);
- image1.Canvas.LineTo(X-4,Y-18);
- image1.Canvas.MoveTo(X-7,Y-16);
- image1.Canvas.LineTo(X-7,Y-26);
- image1.Canvas.MoveTo(X+3,Y-24);
- image1.Canvas.LineTo(X-7,Y-26);
- image1.Canvas.MoveTo(X+8,Y-5);
- image1.Canvas.LineTo(X+23,Y+7);
- image1.Canvas.MoveTo(X+3,Y-1);
- image1.Canvas.LineTo(X+18,Y+11);
- image1.Canvas.MoveTo(X+8,Y-5);
- image1.Canvas.LineTo(X+3,Y-1);
- image1.Canvas.MoveTo(X+23,Y+7);
- image1.Canvas.LineTo(X+25,Y+3);
- image1.Canvas.MoveTo(X+18,Y+11);
- image1.Canvas.LineTo(X+14,Y+13);
- image1.Canvas.MoveTo(X+25,Y+3);
- image1.Canvas.LineTo(X+25,Y+12);
- image1.Canvas.MoveTo(X+14,Y+13);
- image1.Canvas.LineTo(X+25,Y+12);
- image1.Canvas.MoveTo(X-8,Y+5);
- image1.Canvas.LineTo(X-23,Y-7);
- image1.Canvas.MoveTo(X-3,Y+1);
- image1.Canvas.LineTo(X-18,Y-11);
- image1.Canvas.MoveTo(X-8,Y+5);
- image1.Canvas.LineTo(X-3,Y+1);
- image1.Canvas.MoveTo(X-23,Y-7);
- image1.Canvas.LineTo(X-25,Y-3);
- image1.Canvas.MoveTo(X-18,Y-11);
- image1.Canvas.LineTo(X-14,Y-13);
- image1.Canvas.MoveTo(X-25,Y-3);
- image1.Canvas.LineTo(X-25,Y-12);
- image1.Canvas.MoveTo(X-14,Y-13);
- image1.Canvas.LineTo(X-25,Y-12);
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=mDrawWidth;
- end
- else if(mType=13)then
- begin
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=4;
- image1.Canvas.Ellipse(X-100,Y-50,X,Y);
- image1.Canvas.Arc(X-100,Y-30,X,Y+20,X-100,Y-5,X,Y-5);
- image1.Canvas.MoveTo(X-100,Y-25);
- image1.Canvas.LineTo(X-100,Y-5);
- image1.Canvas.MoveTo(X,Y-25);
- image1.Canvas.LineTo(X,Y-5);
- image1.Canvas.MoveTo(X-55,Y-20);
- image1.Canvas.LineTo(X-75,Y-10);
- image1.Canvas.MoveTo(X-60,Y-23);
- image1.Canvas.LineTo(X-80,Y-13);
- image1.Canvas.MoveTo(X-60,Y-23);
- image1.Canvas.LineTo(X-55,Y-20);
- image1.Canvas.MoveTo(X-70,Y-9);
- image1.Canvas.LineTo(X-75,Y-10);
- image1.Canvas.MoveTo(X-83,Y-15);
- image1.Canvas.LineTo(X-80,Y-13);
- image1.Canvas.MoveTo(X-84,Y-10);
- image1.Canvas.LineTo(X-70,Y-9);
- image1.Canvas.MoveTo(X-84,Y-10);
- image1.Canvas.LineTo(X-83,Y-15);
- image1.Canvas.MoveTo(X-45,Y-30);
- image1.Canvas.LineTo(X-25,Y-40);
- image1.Canvas.MoveTo(X-40,Y-27);
- image1.Canvas.LineTo(X-20,Y-37);
- image1.Canvas.MoveTo(X-40,Y-27);
- image1.Canvas.LineTo(X-45,Y-30);
- image1.Canvas.MoveTo(X-30,Y-41);
- image1.Canvas.LineTo(X-25,Y-40);
- image1.Canvas.MoveTo(X-17,Y-35);
- image1.Canvas.LineTo(X-20,Y-37);
- image1.Canvas.MoveTo(X-16,Y-40);
- image1.Canvas.LineTo(X-30,Y-41);
- image1.Canvas.MoveTo(X-16,Y-40);
- image1.Canvas.LineTo(X-17,Y-35);
- image1.Canvas.MoveTo(X-18,Y-10);
- image1.Canvas.LineTo(X-38,Y-20);
- image1.Canvas.MoveTo(X-23,Y-7);
- image1.Canvas.LineTo(X-43,Y-17);
- image1.Canvas.MoveTo(X-23,Y-7);
- image1.Canvas.LineTo(X-18,Y-10);
- image1.Canvas.MoveTo(X-35,Y-22);
- image1.Canvas.LineTo(X-38,Y-20);
- image1.Canvas.MoveTo(X-46,Y-15);
- image1.Canvas.LineTo(X-43,Y-17);
- image1.Canvas.MoveTo(X-35,Y-22);
- image1.Canvas.LineTo(X-46,Y-23);
- image1.Canvas.MoveTo(X-46,Y-15);
- image1.Canvas.LineTo(X-46,Y-23);
- image1.Canvas.MoveTo(X-82,Y-40);
- image1.Canvas.LineTo(X-62,Y-30);
- image1.Canvas.MoveTo(X-77,Y-43);
- image1.Canvas.LineTo(X-57,Y-33);
- image1.Canvas.MoveTo(X-77,Y-43);
- image1.Canvas.LineTo(X-82,Y-40);
- image1.Canvas.MoveTo(X-65,Y-28);
- image1.Canvas.LineTo(X-62,Y-30);
- image1.Canvas.MoveTo(X-54,Y-35);
- image1.Canvas.LineTo(X-57,Y-33);
- image1.Canvas.MoveTo(X-65,Y-28);
- image1.Canvas.LineTo(X-54,Y-27);
- image1.Canvas.MoveTo(X-54,Y-35);
- image1.Canvas.LineTo(X-54,Y-27);
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=mDrawWidth;
- end
- else if(mType=15)then
- begin
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=4;
- image1.Canvas.MoveTo(X-40,Y-15);
- image1.Canvas.LineTo(X+40,Y-15);
- image1.Canvas.MoveTo(X+40,Y-15);
- image1.Canvas.LineTo(X+40,Y+15);
- image1.Canvas.MoveTo(X-40,Y+15);
- image1.Canvas.LineTo(X+40,Y+15);
- image1.Canvas.MoveTo(X-40,Y-15);
- image1.Canvas.LineTo(X-40,Y-9);
- image1.Canvas.MoveTo(X-40,Y+9);
- image1.Canvas.LineTo(X-40,Y+15);
- image1.Canvas.Rectangle(X-45,Y-9,X-27,Y+9);
- image1.Canvas.Rectangle(X-35,Y+15,X+35,Y+21);
- image1.Canvas.pen.Width:=1;
- image1.Canvas.pen.Color:=clblack;
- image1.Canvas.Brush.color:=clgreen;
- image1.Canvas.Rectangle(X+30,Y-10,X+38,Y);
- image1.Canvas.Brush.color:=clred;
- image1.Canvas.Rectangle(X+20,Y-10,X+30,Y);
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=mDrawWidth;
- end
- else if(mType=16)then
- begin
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=4;
- image1.Canvas.Rectangle(X-40,Y-15,X+40,Y+15);
- image1.Canvas.Rectangle(X-37,Y-12,X+37,Y);
- image1.Canvas.pen.Width:=1;
- image1.Canvas.pen.Color:=clblack;
- image1.Canvas.Brush.color:=cl3DDkShadow;
- image1.Canvas.Rectangle(X+25,Y+5,X+35,Y+9);
- image1.Canvas.Brush.color:=clgreen;
- image1.Canvas.Ellipse(X+15,Y+2,X+20,Y+12);
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=mDrawWidth;
- end
- else if(mType=17)then
- begin
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=4;
- image1.Canvas.Rectangle(X-20,Y-45,X+20,Y+45);
- image1.Canvas.Rectangle(X-15,Y-35,X+15,Y-28);
- image1.Canvas.Rectangle(X-15,Y-23,X+15,Y-15);
- image1.Canvas.RoundRect(X-10,Y-20,X+10,Y-18,4,1);
- //image1.Canvas.Rectangle(X-10,Y-20,X+10,Y-18);
- image1.Canvas.pen.Width:=1;
- image1.Canvas.pen.Color:=clblack;
- image1.Canvas.Brush.color:=clgreen;
- image1.Canvas.Ellipse(X+3,Y+3,X-3,Y-3);
- image1.Canvas.MoveTo(X-15,Y+20);
- image1.Canvas.LineTo(X+14,Y+20);
- image1.Canvas.MoveTo(X-15,Y+27);
- image1.Canvas.LineTo(X+14,Y+27);
- image1.Canvas.MoveTo(X-15,Y+34);
- image1.Canvas.LineTo(X+14,Y+34);
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=mDrawWidth;
- end
- else if(mType=18)then
- begin
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=4;
- image1.Canvas.Ellipse(X-70,Y-50,X,Y);
- image1.Canvas.Arc(X-70,Y-30,X,Y+20,X-100,Y-5,X,Y-5);
- image1.Canvas.MoveTo(X-70,Y-25);
- image1.Canvas.LineTo(X-70,Y-5);
- image1.Canvas.MoveTo(X,Y-25);
- image1.Canvas.LineTo(X,Y-5);
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=mDrawWidth;
- end
- else if(mType=19)then
- begin
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=4;
- image1.Canvas.MoveTo(X-40,Y);
- image1.Canvas.LineTo(X,Y-30);
- image1.Canvas.MoveTo(X,Y-30);
- image1.Canvas.LineTo(X+40,Y);
- image1.Canvas.MoveTo(X+40,Y);
- image1.Canvas.LineTo(X,Y+30);
- image1.Canvas.MoveTo(X,Y+30);
- image1.Canvas.LineTo(X-40,Y);
- image1.Canvas.MoveTo(X+40,Y+20);
- image1.Canvas.LineTo(X,Y+50);
- image1.Canvas.MoveTo(X,Y+50);
- image1.Canvas.LineTo(X-40,Y+20);
- image1.Canvas.MoveTo(X+40,Y+20);
- image1.Canvas.LineTo(X+40,Y);
- image1.Canvas.MoveTo(X-40,Y);
- image1.Canvas.LineTo(X-40,Y+20);
- image1.Canvas.MoveTo(X,Y+30);
- image1.Canvas.LineTo(X,Y+50);
- image1.Canvas.MoveTo(X-20,Y-8);
- image1.Canvas.LineTo(X,Y+7);
- image1.Canvas.MoveTo(X-12,Y-14);
- image1.Canvas.LineTo(X+8,Y+1);
- image1.Canvas.MoveTo(X-12,Y-14);
- image1.Canvas.LineTo(X-20,Y-8);
- image1.Canvas.MoveTo(X-5,Y+10);
- image1.Canvas.LineTo(X,Y+7);
- image1.Canvas.MoveTo(X+13,Y-2);
- image1.Canvas.LineTo(X+8,Y+1);
- image1.Canvas.MoveTo(X-5,Y+10);
- image1.Canvas.LineTo(X+14,Y+14 );
- image1.Canvas.MoveTo(X+13,Y-2);
- image1.Canvas.LineTo(X+14,Y+14);
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=mDrawWidth;
- end
- else if(mType=20)then
- begin
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=4;
- image1.Canvas.MoveTo(X+35,Y-30);
- image1.Canvas.LineTo(X+35,Y+30);
- image1.Canvas.MoveTo(X+35,Y+30);
- image1.Canvas.LineTo(X-35,Y+30);
- image1.Canvas.MoveTo(X-35,Y+30);
- image1.Canvas.LineTo(X-35,Y-30);
- image1.Canvas.Arc(X+35,Y+10,X-35,Y-90,X-35,Y-30,X+35,Y-30);
- image1.Canvas.MoveTo(X+55,Y+15);
- image1.Canvas.LineTo(X+35,Y+30);
- image1.Canvas.MoveTo(X+55,Y+15);
- image1.Canvas.LineTo(X+55,Y-45);
- image1.Canvas.MoveTo(X+35,Y-30);
- image1.Canvas.LineTo(X+55,Y-45);
- image1.Canvas.MoveTo(X-35,Y-30);
- image1.Canvas.LineTo(X-15,Y-45);
- image1.Canvas.Arc(X+55,Y-5,X-15,Y-115,X-15,Y-45,X+25,Y-6);
- //设置画笔的线宽
- image1.Canvas.Pen.Width:=mDrawWidth;
- end;
- //保存图象
- rect.Left:=0;
- rect.Top:=0;
- rect.Right:=Image1.Width;
- rect.Bottom:=Image1.Height;
- Bitmap.Width:=Image1.Width;
- Bitmap.Height:=Image1.Height;
- Bitmap.Canvas.CopyRect(rect,Image1.Canvas,rect);
- //设置修改标志
- mModifyFlag:=true;
- end;
- end;
- procedure TFormCanvas.FormShow(Sender: TObject);
- begin
- //初始化当前正在绘制的图元类型
- mType:=0;
- //初始化当前正在绘制的图元线宽
- mDrawWidth:=StrToInt(FormPaintbrush.ComboBoxWidth.text);
- //初始化当前正在绘制的图元颜色($000000代表黑色,$FFFFFF代表白色,$0000FF代表红色)
- FormPaintbrush.Shape1.Brush.Color:=FormPaintbrush.ColorBox.Selected;
- mDrawColor:=FormPaintbrush.Shape1.Brush.Color;
- //创建Bitmap,并设置其宽度和高度
- Bitmap:=TBitmap.Create;
- Bitmap.Width:=Image1.Width;
- Bitmap.Height:=Image1.Height;
- //初始化工具条的down状态(即是否下压)
- FormPaintbrush.ToolButtonLine.Down:=false;
- FormPaintbrush.ToolButtonRectangle.Down:=false;
- FormPaintbrush.ToolButtonEllipse.Down:=false;
- //初始化修改标志
- mModifyFlag:=false;
- //将imagecopy隐藏
- imagecopy.Hide;
- //将CursorColor隐藏
- CursorColor.Hide;
- end;
- end.