How can I get the mouse position on an image after uploading it on axes

2 次查看(过去 30 天)
Hi,
I want to display the mouse position on my GUI. The problem is that it works on the axes. But after uploading the image it doesn't work any more. What is the problem? Or is there any other possibility to do it?
% --- Executes on mouse press over axes background.
function axes1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
c = get (gca, 'CurrentPoint');
x = c(1,1);
y = c(1,2);
set(handles.xPos, 'string', ['x loc:' num2str(x)]); % update text for x loc
set(handles.yPos, 'string', ['y loc:' num2str(y)]); % update text for y loc

回答(1 个)

Guillaume
Guillaume 2018-12-20
By default Image objects capture mouse clicks. So if an Image is displayed in an axes, when you click on it it's the ButtonDownFcn of the Image that gets called, not the axes one.
You can easily turn that off but setting the HitTest property of the Image to off.
%image creation using either imhsow, image, imagesc, whatever...
himage = imshow(something)
himage.HitTest = 'off'; %image won't capture mouse clicks, the axes will instead.
  1 个评论
Ouael Chkoundali
Ouael Chkoundali 2018-12-22
Hi Guillaume,
thanks for your answer. Is there any possibility to show the mouse position without clicking on the axes? It works on a figure but i couldn't do it on axes?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by