zl程序教程

您现在的位置是:首页 >  系统

当前栏目

基于MATLAB的仿windows画图板功能的实现

WindowsMATLAB 实现 基于 功能
2023-09-11 14:15:33 时间

1.仿真预览

2.部分核心代码

% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu2
global rgb;
str=get(handles.popupmenu2,'string');
index=get(handles.popupmenu2,'value');
str1=char(str(index));
switch (str1)
    case 'red'
        rgb=[1,0,0];
    case 'green'
        rgb=[0,1,0];
    case 'blue'
        rgb=[0,0,1];
    case 'black'
        rgb=[0,0,0];
end
set(handles.edit1,'foregroundcolor',rgb);
set(handles.edit2,'foregroundcolor',rgb);
set(handles.text3,'foregroundcolor',rgb);
% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



% --- Executes on mouse press over axes background.
function axes1_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to axes1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% set(gcf, 'Interruptible', 'off','BusyAction', 'cancel');
% set(gcf, 'WindowButtonMotionFcn', '','Interruptible', 'off');
cla
set(handles.edit1,'string','');
set(handles.edit2,'string','');
set(handles.text3,'string','');
set(handles.pushbutton2,'enable','off');
set(handles.pushbutton3,'enable','off');
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[FileName,PathName] = uiputfile({'*.jpg','JPEG(*.jpg)';...
                                 '*.bmp','Bitmap(*.bmp)';...
                                 '*.gif','GIF(*.gif)';...
                                 '*.*',  'All Files (*.*)'},...
                                 'Save Picture','Untitled');
if FileName==0
    return;
else
    h=getframe(handles.axes1);
    imwrite(h.cdata,[PathName,FileName]);
end


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
CleanGlobals;
close(gcf);

% --- Executes on selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu3 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu3
global graph flag h mark;
h=[];
str=get(handles.popupmenu3,'string');
index=get(handles.popupmenu3,'value');
graph=char(str(index));
popu={};
switch(graph)
    case '点线'
        popu={'. 点';'+ 号';'O 圈';'* 号';'v 三角号'};
        set(handles.popupmenu1,'string',popu);
        set(handles.popupmenu1,'value',1);
        set(handles.text4,'string','选择marker')
        mark='.';
    otherwise
        popu={'- 实线';'--虚线';': 点线';'-.虚点线';};
        set(handles.popupmenu1,'string',popu);
        set(handles.popupmenu1,'value',1);
        set(handles.text4,'string','选择LineTyple')
        mark='-';
end

C-02