用鼠标在图象上拉矩形框(如PhotoShop中有这项功能),怎么实现

xyz_no1 2001-08-31 01:37:46
鼠标左键在按下移动的过程中,矩形框随着变化
...全文
139 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
fhb 2001-08-31
  • 打赏
  • 举报
回复
看一下
http://www.truevcl.com
pathe 2001-08-31
  • 打赏
  • 举报
回复
var
bIsDrawing : boolean;
iOldX, iOldY : integer;
iStartX,iStartY : integer;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
bIsDrawing := True;
iStartX := x;
iStartY := y;
iOldX := x;
iOldY := y;
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if bIsDrawing then
begin
with Image1.Canvas do
begin

Pen.Mode := pmXor;
brush.Color := clred;

Rectangle (Rect(iStartX,iStartY,iOldX,iOldY));
Rectangle (Rect(iStartX,iStartY,x,y));
iOldX := x;
iOldY := y;
end;
end;
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
bIsdrawing := false;
end;
老板来了,没做完,但也差不多了,你的把Rectangle()换成Polyline或者自己写个画巨型的寒数!
记着将pen的模式设回去!
pathe 2001-08-31
  • 打赏
  • 举报
回复
你不能用Rectangle(),我不是说了吗?那是老板来了,
用来凑数的,你应该自己写个用线画巨型的函数,
因为rectangle()是会用brush填充巨型的!
不行了,对不住了,不能多说了!
xyz_no1 2001-08-31
  • 打赏
  • 举报
回复
按pathe(睡斛)的做法,基本可行,可还有些问题:
1、画图的位置与鼠标的位置不对应,我用ClientToScreen了还不行
2、画出的矩形框会把原来的图像掩盖了,不知是否Canvas.Mode设置出了问题?

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧