我无法在GUI轴上显示图像。问题是我不能使用imgshow()或image()等。 我一直在将GUI中的轴用作白板,以便人们可以在其上进行绘制,但是我想向其添加图像,并且仍然能够继续绘制。这种方法的问题在于,在轴的“子级”(Children)属性上将图形存储为“线”,因此实际添加的图像必须是“线”数组。任何想法如何解决这个问题?谢谢。
以下是一些代码,作为我要执行的操作的示例:
% --- 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...