本人做了一个GUI界面,目标是实现在axes坐标中导入一张照片,然后可以在照片上用鼠标画圈,然后就可以计算出画圈部分占照片总面积的比例;同时也可以用白色覆盖多余部分(可以看成橡皮擦功能吧?)
但目前:画圈,橡皮擦功能的代码是基于axes坐标轴实现的,也就是说,实际上照片本身并没有改变,画的圈只是和照片在一个坐标中同时显示出来而已,如果保存照片的话,画的圈和擦掉的部分都不会在保存的照片中体现。。。我该怎么改?先谢过了!下面是画圈,和橡皮擦的功能的代码。。。其实本质是一样的
function figure_EasyPaint_WindowButtonDownFcn(hObject, eventdata, handles)
% hObject handle to figure_EasyPaint (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global flag x0 y0 x y PaintFlag Eflag;
flag = 1; %鼠标单击
cp = get(handles.axes_before, 'CurrentPoint'); %axes_before 为坐标轴Tag
x = cp(1,1);
y = cp(1,2);
if PaintFlag % 选择画圈按钮
plot(handles.axes_before, x, y, 'Color', [1 0 0]);
end
if Eflag %选择橡皮擦按钮
set(gcf, 'CurrentAxes', handles.axes_before);
plot(handles.axes_before, x, y, 'Color', [1 1 1]);
end
x0 = x;
y0 = y;
guidata(hObject, handles);
% --- Executes on mouse motion over figure - except title and menu.
function figure_EasyPaint_WindowButtonMotionFcn(hObject, eventdata, handles)
% hObject handle to figure_EasyPaint (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global flag x0 y0 x y PaintFlag Eflag;
x0 = x;
y0 = y;
cp = get(handles.axes_before, 'CurrentPoint');
x = cp(1,1);
y = cp(1,2);
if flag && PaintFlag
temp = get(handles.slider1, 'Value');
LineWidth = temp + 2;
plot(handles.axes_before, [x0 x], [y0 y], 'LineWidth', LineWidth, 'Color', [1 0 0]);
end
if flag && Eflag
set(gcf, 'CurrentAxes', handles.axes_before);
temp = get(handles.slider1, 'Value');
LineWidth = temp + 2;
plot(handles.axes_before, [x0 x], [y0 y], 'LineWidth', LineWidth, 'Color', [1 1 1]);
end
guidata(hObject, handles);
% --- Executes on mouse press over figure background, over a disabled or
% --- inactive control, or over an axes background.
function figure_EasyPaint_WindowButtonUpFcn(hObject, eventdata, handles)
% hObject handle to figure_EasyPaint (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global flag PaintFlag Eflag;
flag = 0;
PaintFlag = 0;
Eflag = 0;
guidata(hObject, handles);