필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Ouael Chkoundali
Ouael Chkoundali 2018년 12월 20일
댓글: Ouael Chkoundali 2018년 12월 22일
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