Problem drawing lines by dragging the mouse

1 回表示 (過去 30 日間)
Sawsan
Sawsan 2012 年 11 月 6 日
回答済み: Vasilisa Iatckova 2022 年 8 月 15 日
I want to draw a set of disconnected lines on top of an image by dragging the mouse while the left button is pressed. However, if I click on a previously drawn line to specify the starting point of the next line, the callback function is not being called and I don't get the point. Here is my code:
function main_test
S.fH = figure('menubar','none');
im = imread( 'image.jpg' );
S.aH = axes;
S.iH = imshow( im ); hold on
axis image;
X = [];
Y = [];
set(S.aH,'ButtonDownFcn',@startDragFcn)
set(S.iH,'ButtonDownFcn',@startDragFcn)
set(S.fH, 'WindowButtonUpFcn', @stopDragFcn);
function startDragFcn(varargin)
set( S.fH, 'WindowButtonMotionFcn', @draggingFcn );
pt = get(S.aH, 'CurrentPoint');
x = pt(1,1);
y = pt(1,2);
X = x;
Y = y;
end
function draggingFcn(varargin)
pt = get(S.aH, 'CurrentPoint');
x = pt(1,1);
y = pt(1,2);
X = [X x];
Y = [Y y];
plot(X, Y, 'r', 'LineWidth', 6);
hold on
drawnow
end
function stopDragFcn(varargin)
set(S.fH, 'WindowButtonMotionFcn', ''); %eliminate fcn on release
end
end
Would you please help me to find the problem in this.
Thank you in a advance..
cheers, Sawsan

回答 (1 件)

Vasilisa Iatckova
Vasilisa Iatckova 2022 年 8 月 15 日
Setting the hittest for the line to off might help.

カテゴリ

Help Center および File ExchangeGraphics Objects についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by