У меня возникают проблемы при попытке отобразить изображение на оси графического интерфейса. Проблема в том, что я не могу использовать imgshow () или image () и т.д ...
Я использовал оси в своем графическом интерфейсе в качестве белой доски, чтобы люди могли рисовать на ней, но я хотел бы добавить к ней изображение и при этом продолжать рисовать. Проблема этого подхода заключается в том, что чертежи хранятся в виде линий на атрибуте осей «Дети», поэтому фактическим добавленным изображением должен быть массив строк. Есть идеи как решить это? Thx.
Вот пример кода, который я пытаюсь сделать:
% --- Executes on mouse press over axes background.
function axesUserDraw_ButtonDownFcn(hObject, eventdata, handles)
userDraw(handles);
function userDraw(handles)
A=handles.axesUserDraw;
set(A,'buttondownfcn',@start_pencil)
function start_pencil(src,eventdata)
coords=get(src,'currentpoint'); %since this is the axes callback, src=gca
x=coords(1,1,1);
y=coords(1,2,1);
r=line(x, y, 'color', 'black', 'LineWidth', 4, 'hittest', 'off'); %turning hittset off allows you to draw new lines that start on top of an existing line.
set(gcf,'windowbuttonmotionfcn',{@continue_pencil,r})
set(gcf,'windowbuttonupfcn',@done_pencil)
function continue_pencil(src,eventdata,r)
%Note: src is now the figure handle, not the axes, so we need to use gca.
coords=get(gca,'currentpoint'); %this updates every time i move the mouse
x=coords(1,1,1);
y=coords(1,2,1);
%get the line's existing coordinates and append the new ones.
lastx=get(r,'xdata');
lasty=get(r,'ydata');
newx=[lastx x];
newy=[lasty y];
set(r,'xdata',newx,'ydata',newy);
function done_pencil(src,evendata)
%all this function does is turn the motion function off
set(gcf,'windowbuttonmotionfcn','')
set(gcf,'windowbuttonupfcn','')
% --- Executes on button press in clearDraw.
function clearDraw_Callback(hObject, eventdata, handles)
cla(handles.axesUserDraw);
set(handles.drawingTestResult,'String',' ');
% --- Executes on button press in importImage.
function importImage_Callback(hObject, eventdata, handles)
% Code for converting image into Lines to display it on the axes...