Drawing with mouse motion in a GUI-image
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi, I want to draw a line in an image displayed in a GUI. Matlab has a good example which works great for an individual figure:
However, while running it from a callback function in the GUI, I am having issues:
- Defining handle for the image-axis is not allowed by WindowButtonDownFcn.
- I can use the handle of the GUI-figure (which is an alternative of the point above), but how do I extract the co-ordinates for later use?
Example code (Matlab)
function draw_lines
% Click the left mouse button to define a point
% Drag the mouse to draw a line to the next point and
% left click again
% Right click the mouse to stop drawing
%
figure('WindowButtonDownFcn',@wbdcb)
ah = axes('DrawMode','fast');
axis ([1 10 1 10])
function wbdcb(src,evnt)
if strcmp(get(src,'SelectionType'),'normal')
[x,y,str] = disp_point(ah);
hl = line('XData',x,'YData',y,'Marker','.');
text(x,y,str,'VerticalAlignment','bottom');drawnow
set(src,'WindowButtonMotionFcn',@wbmcb)
elseif strcmp(get(src,'SelectionType'),'alt')
set(src,'WindowButtonMotionFcn','')
[x,y,str] = disp_point(ah);
text(x,y,str,'VerticalAlignment','bottom');drawnow
end
function wbmcb(src,evnt)
[xn,yn,str] = disp_point(ah);
xdat = [x,xn];
ydat = [y,yn];
set(hl,'XData',xdat,'YData',ydat);
end
end
function [x,y,str] = disp_point(ah)
cp = get(ah,'CurrentPoint');
x = cp(1,1);y = cp(1,2);
str = ['(',num2str(x,'%0.3g'),', ',num2str(y,'%0.3g'),')'];
end
end
댓글 수: 2
Image Analyst
2016년 7월 18일
Are you using GUIDE? Or are you trying to do it the hard way and define all the properties/settings and callbacks yourself?
And what's in the axes control? If there is something like an image you'll have to set a callback for the image since it lies on top of the axes, or else set the hittest for the image to be off.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!