Drag and drop Image by axes attachment

I am creating a gui involving drag and dropping images. I can drag axes and attach images using imshow however the dragging functionality is lost upon attachment. What is the reason for this? With some other online help here is the code I used:
%drawing axes and attaching figure
ax = axes('Parent',tab3,'Position',[.15 .15 .1 .1],'ButtonDownFcn',@dragObject);
handles = guihandles(ax);
img=imread('Cyclindrical.PNG');
imshow(img,'parent',ax,'ButtonDownFcn',@dragObject);
grab and drag functions are as follows:
function dragObject(hObject,eventdata)
dragging = hObject;
oldPos = get(gcf,'CurrentPoint');
disp(oldPos)
end
function dropObject(hObject,eventdata)
if ~isempty(dragging)
newPos = get(gcf,'CurrentPoint');
dPos = newPos - oldPos;
set(dragging,'Position',get(dragging,'Position') + [dPos(1:2) 0 0]);
dragging = [];
end
end

1 commentaire

Skander Ayoub
Skander Ayoub le 31 Août 2021
Hi Jonathan,
Did you manage to solve your problem ? I am also facing this issue.

Connectez-vous pour commenter.

Réponses (0)

Commenté :

le 31 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by