1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| function test
fig=gcf;
hold off;
hIm = imshow('cameraman.tif');
hSP = imscrollpanel(fig,hIm);
set(hSP,'Units','normalized',...
'Position',[0 0.1 0.7 1]);
hold on %sinon "fill" va écraser l'image
h=impoly();
%fonction non documentée pour tous les imroi, susceptible d'évoluer avec les futures versions...
hchild = findobj(h,'Type','line','-or','Type','patch');
cmenu = get(hchild(1),'UiContextMenu'); % pour conserver le menu existant
%cmenu = uicontextmenu('Parent',fig); % ou pour l'écraser
item1 = uimenu(cmenu, 'Label', 'Red', 'Callback',{@FillColor,h,'r'});
item2 = uimenu(cmenu, 'Label', 'Blue', 'Callback',{@FillColor,h,'b'});
set(hchild,'UIContextMenu',cmenu); %pour associer le menu contextuel aux enfants de l'impoly
function FillColor(hObject,eventdata,hImPoly,color)
pos=getPosition(hImPoly);
fill(pos(:,1),pos(:,2),color); |