怎么样删除用framrect画的虚线矩形框? (100分)

  • 主题发起人 主题发起人 stonesll
  • 开始时间 开始时间
S

stonesll

Unregistered / Unconfirmed
GUEST, unregistred user!
我想用鼠标在图片上画任意的矩形框,就象photoshop中选择区域一样,要动态的模拟画虚线矩形框,
这样每次我都必须删除上一次的矩形框。最后放下鼠标左键,矩形框生成。
可是由于我在image1MouseMove事件中每次都执行image1.Repaint,所以闪烁很严重。不知有没有好办法实现这种对图象的选择

canvas.brush.Style := bsDiagCross;
canvas.FrameRect(rect_ll);//画矩形框
 

//实现流动线效果,如Photoshop中选择图形时的状态,摘自于本论坛
var
Form1: TForm1;
Counter :Byte;

implementation

{$R *.dfm}
procedure MovingDots(X,Y: Integer; TheCanvas: TCanvas); stdcall;
begin
Counter := Counter shl 1;
if Counter = 0 then Counter := 1;
if (Counter and 224) > 0 then
TheCanvas.Pixels[X,Y] :=clBtnFace
else
TheCanvas.Pixels[X,Y] :=clBlack;
end;


procedure TForm1.Timer1Timer(Sender: TObject);
begin
LineDDA(30,30,200,30,@MovingDots,LongInt(Canvas));
LineDDA(200,30,200,150,@MovingDots,LongInt(Canvas));
LineDDA(200,150,30,150,@MovingDots,LongInt(Canvas));
LineDDA(30,150,30,30,@MovingDots,LongInt(Canvas));
end;
 
一般实现这种情况可用XOR方式操作
 
倒,被盗版了,^_^

var
Form1: TForm1;
draw :Boolean;
p1,p2 :TPoint;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
draw :=False;
Image1.Canvas.Pen.Style :=psDot;
Image1.Canvas.Brush.Style :=bsClear;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
draw :=True;
p1 :=Point(x,y);
p2 :=p1;
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if draw then
begin
with Image1 do begin
Canvas.Rectangle(p1.x,p1.y,p2.x,p2.y);
Canvas.Pen.Mode :=pmNotXor;
p2 :=Point(x,y);
Canvas.Rectangle(p1.x,p1.y,p2.x,p2.y);
end;
end;
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if draw then
begin
with Image1 do begin
Canvas.Rectangle(p1.x,p1.y,p2.x,p2.y);
Canvas.Pen.Mode :=pmCopy;
p2 :=Point(x,y);
Canvas.Rectangle(p1.x,p1.y,p2.x,p2.y);
end;
end;
draw :=False;
end;

至于如何形成流动线的效果,看看这里:http://www.delphibbs.com/delphibbs/dispq.asp?lid=930660
 
tyn ,你好象并没有删除矩形框,你能告诉我pmNotXor这种模式的用处吗?
如果我象CLICK 图象时,矩形框消失,可以做到吗?谢谢!
 
现在好了,先画一个矩形框,然后点击按钮消失。

var
Form1: TForm1;
draw :Boolean;
p1,p2 :TPoint;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
draw :=False;
Image1.Canvas.Pen.Style :=psDot;
Image1.Canvas.Brush.Style :=bsClear;

end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
draw :=True;
p1 :=Point(x,y);
p2 :=p1;

end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin

if draw then
begin
with Image1 do begin
Canvas.Rectangle(p1.x,p1.y,p2.x,p2.y);
Canvas.Pen.Mode :=pmNotXor;
p2 :=Point(x,y);
Canvas.Rectangle(p1.x,p1.y,p2.x,p2.y);
end;
end;

end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if draw then
begin
with Image1 do begin
Canvas.Rectangle(p1.x,p1.y,p2.x,p2.y);
p2 :=Point(x,y);
Canvas.Rectangle(p1.x,p1.y,p2.x,p2.y);
end;
end;
draw :=False;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Image1.Canvas.Rectangle(p1.x,p1.y,p2.x,p2.y);
Image1.Canvas.Pen.Mode :=pmCopy;
end;
 
接受答案了.
 
后退
顶部