Drawing with mouse motion in a GUI-image
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Image Analyst
il 18 Lug 2016
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.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!