请问在image如何编写取消上几步画的图案呢?
解决方案 »
- 用采集速率10MHz以上的同步高速AD卡 用多线程
- 小弟不才,在delphi2010居然找不到在哪里打开工程文件
- 散分,登陆验证码11111
- 请问,如果用DELPHI做这样的外挂,需要什么技术?
- 急:连接access数据库的问题?
- 怎样将sql数据库查询结果赋给一个数组???急!
- 自定义的record数组能不能直接赋值???
- 如何得到系统的菜单?
- 如何新建一个VCL组件,继承自TEdit
- 请教:不连接其它数据库,我怎么在程序中自定义一个数据表 datatable,以存储二维数据?,且能绑定到dbgrid
- 请问这段代码有什么错?拜托了
- 这是什么错?---Statement expected, but 'var' found
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons, AppEvnts, jpeg, Menus, ActnList,
ComCtrls, ToolWin, ImgList,TypeDefineU;
type
TForm1 = class(TForm)
imgPaint: TImage;
ToolBar1: TToolBar;
tbtBack: TToolButton;
tbtForward: TToolButton;
ActionList1: TActionList;
actBack: TAction;
actForward: TAction;
ToolButton6: TToolButton;
cmbShape: TComboBox;
cmbWidth: TComboBox;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure imgPaintMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure imgPaintMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure imgPaintMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure actBackExecute(Sender: TObject);
procedure actForwardExecute(Sender: TObject);
private
FDownPoint,FUpPoint:TPoint;
FGShape:array[0..MaxCount-1] of TGShape;
Fbitmap:TBitmap;
FCount,FMaxCount:Integer;//the count of FGShape;
procedure BackBitmap;
public end;var
Form1: TForm1;
implementation
uses math, DateUtils;
{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
FCount:=0;
Fbitmap:=TBitmap.Create;
with Fbitmap do
begin
//Canvas.Pen.Width:=cmbWidth.ItemIndex+1;
Canvas.Pen.Style:=psSolid;
Canvas.Pen.Mode:=pmMask;
Canvas.Brush.Color:=clWhite;
Width:=ClientWidth;
Height:=ClientHeight;
end;
BackBitmap;
//imgPaint.Canvas.CopyRect(imgPaint.Canvas.ClipRect,Fbitmap.Canvas,imgPaint.Canvas.ClipRect);end;procedure TForm1.BackBitmap;
var
j:integer;
begin
With Fbitmap.Canvas do
begin
Brush.Color:=clWhite;
Pen.Color:=clWhite;
FillRect(ClipRect);
for j:=0 to FCount-1 do
begin
Pen.Width:=FGShape[j].PenWidth;;
Pen.Color:=FGShape[j].PenColor;
Brush.Color:=FGShape[j].BrushColor; case FGShape[j].Shape of
ssLine:
begin
MoveTo(FGShape[j].DownPoint.X,FGShape[j].DownPoint.Y,);
LineTo(FGShape[j].UPPoint.X,FGShape[j].UPPoint.Y);
end;
ssRectangle:
Rectangle(FGShape[j].DownPoint.X , FGShape[j].DownPoint.Y,
FGShape[j].UPPoint.X , FGShape[j].UPPoint.Y);
ssEllipse:
Ellipse(FGShape[j].DownPoint.X , FGShape[j].DownPoint.Y,
FGShape[j].UPPoint.X , FGShape[j].UPPoint.Y);
end;
end;
end;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
Fbitmap.Free;
end;procedure TForm1.imgPaintMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDownPoint.X:=X;
FDownPoint.Y:=Y;
end;procedure TForm1.imgPaintMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FUpPoint.X:=X;
FUpPoint.Y:=Y;
if FCount<MaxCount-1 then
begin
Randomize;
FGShape[FCount].DownPoint:=FDownPoint;
FGShape[FCount].UpPoint:=FUpPoint;
FGShape[FCount].PenWidth:=cmbWidth.ItemIndex+1;
FGShape[FCount].PenColor:=RandomRange(255,255*255*1); //边线色
//FGShape[FCount].BrushColor:=clWhite; //填充色
FGShape[FCount].BrushColor:=RandomRange(255*255*8,255*255*16);
FGShape[FCount].Shape:=tshapestyle(cmbShape.ItemIndex);
// if mouse ,Down and Up are not a same point,it will be add into FCount
if (FUpPoint.X<>FDownPoint.X) and ((FUpPoint.Y<>FDownPoint.Y)) then
inc(FCount);
FMaxCount:=FCount;
end;
BackBitmap; tbtBack.Enabled:=(FCount>0)
end;procedure TForm1.imgPaintMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
imgPaint.Canvas.CopyRect(imgPaint.Canvas.ClipRect,Fbitmap.Canvas,imgPaint.Canvas.ClipRect);
FUpPoint.X:=X;
FUpPoint.Y:=Y;
if FCount<MaxCount-1 then
begin
FGShape[FCount].DownPoint:=FDownPoint;
FGShape[FCount].UpPoint:=FUpPoint;
FGShape[FCount].PenWidth:=cmbWidth.ItemIndex+1;
//FGShape[FCount].PenColor:=RandomRange(255,255*255*1); //边线色
//FGShape[FCount].BrushColo
FGShape[FCount].PenColor:=RGB(123,125,123);//RGB(0,255,0);//clred;
FGShape[FCount].Shape:=tshapestyle(cmbShape.ItemIndex);;
end;
if ssleft in Shift then
begin
with imgPaint.Canvas do
begin
Pen.Color:=FGShape[FCount].PenColor;
Brush.Color:=FGShape[FCount].BrushColor;
Pen.Width:=FGShape[FCount].PenWidth;
// Pen.Style:=psDashDot ;
Brush.Style:=bsClear ;
case FGShape[FCount].Shape of
ssLine:
begin
MoveTo(FGShape[FCount].DownPoint.X, FGShape[FCount].DownPoint.Y);
LineTo(FGShape[FCount].UPPoint.X, FGShape[FCount].UPPoint.Y);
end;
ssRectangle:
Rectangle(FGShape[FCount].DownPoint.X, FGShape[FCount].DownPoint.Y,
FGShape[FCount].UPPoint.X, FGShape[FCount].UPPoint.Y);
ssEllipse:
Ellipse(FGShape[FCount].DownPoint.X, FGShape[FCount].DownPoint.Y,
FGShape[FCount].UPPoint.X, FGShape[FCount].UPPoint.Y);
end; end;
end;
end;procedure TForm1.actBackExecute(Sender: TObject);
begin
if FCount>0 then
begin
Dec(FCount);
BackBitmap;
imgPaint.Canvas.CopyRect(imgPaint.Canvas.ClipRect,Fbitmap.Canvas,imgPaint.Canvas.ClipRect);
Caption:=inttostr(FCount);
end;
tbtBack.Enabled:=(FCount>0);
tbtForward.Enabled:=(FCount<FMaxCount)
end;procedure TForm1.actForwardExecute(Sender: TObject);
begin
if FCount<FMaxCount then
begin
Inc(FCount);
BackBitmap;
imgPaint.Canvas.CopyRect(imgPaint.Canvas.ClipRect,Fbitmap.Canvas,imgPaint.Canvas.ClipRect);
Caption:=inttostr(FCount);
end;
tbtForward.Enabled:=(FCount<FMaxCount);
tbtBack.Enabled:=(FCount>0)
end;end.
你的提议好象不错,实现也很简单,但是图片占用的内存太大了,所以这种方法不可取
---------
song317(山东老实人) 兄
记录各动作(动作可当作一个对象,可以是个记录,用个数组来统一管理) 就是我采用的方法(我暂时是当作记录),但是我取消的时候不是执行反动作,而是重新画的时候,将有删除标记的不画出来而已
说得非常有道理,嘿嘿。收藏了。