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 Comment

Hi Jonathan,
Did you manage to solve your problem ? I am also facing this issue.

Sign in to comment.

Answers (0)

Asked:

on 27 Feb 2018

Commented:

on 31 Aug 2021

Community Treasure Hunt

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

Start Hunting!