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

5 ビュー (過去 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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by