Drag and drop Image by axes attachment
Show older comments
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
Skander Ayoub
on 31 Aug 2021
Hi Jonathan,
Did you manage to solve your problem ? I am also facing this issue.
Answers (0)
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!