使用matlab实现类似windows系统中的画图小软件,带GUI界面

简介: 使用matlab实现类似windows系统中的画图小软件,带GUI界面

1.仿真效果预览
matlab2022a仿真结果如下:

image.png

2.MATLAB核心程序

function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global flg mark rgb x0 y0 x y rect graph h;
if flg
    switch(graph)
        case '点线'
            currPt=get(gca, 'CurrentPoint');
            x=currPt(1,1);
            y=currPt(1,2);
            line(x,y, 'marker', mark,'color',rgb);
        case '线形'
            x0=x;y0=y;
            currPt=get(gca, 'CurrentPoint');
            x=currPt(1,1);
            y=currPt(1,2);
            line([x0 x], [y0,y],'LineStyle',mark,'color',rgb);
        case '矩形'
            currPt=get(gca, 'CurrentPoint');
            x=currPt(1,1);
            y=currPt(1,2);
            if x~=x0
                if ~isempty(h)
                    set(h,'Visible','off')
                end
                rect=[min([x0,x]),min([y0,y]),abs(x-x0),abs(y-y0)];
                if rect(3)*rect(4)~=0
                    h=rectangle('Position',rect,'LineStyle',':');
                end
            end
        case '椭圆'
            currPt=get(gca, 'CurrentPoint');
            x=currPt(1,1);
            y=currPt(1,2);
            if x~=x0
                if ~isempty(h)
                    set(h,'Visible','off')
                end
                rect=[min([x0,x]),min([y0,y]),abs(x-x0),abs(y-y0)];
                if rect(3)*rect(4)~=0
                    h=rectangle('Position',rect,'Curvature',[1,1],'LineStyle',':');
                end
            end
    end
    set(handles.edit1,'string',num2str(x));
    set(handles.edit2,'string',num2str(y));
    set(handles.text3,'string','Mouse is moving!');
end
 
function figure1_WindowButtonUpFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global flg rgb mark h graph rect;
flg=0;
switch(graph)
    case '矩形'
        set(h,'Visible','off');h=[];
        if rect(3)*rect(4)~=0
            rectangle('Position',rect,'edgecolor',rgb,'LineStyle',mark)
        end
    case '椭圆'
        set(h,'Visible','off');h=[];
        if rect(3)*rect(4)~=0
            rectangle('Position',rect,'Curvature',[1,1],'edgecolor',rgb,'LineStyle',mark)
        end
end
set(handles.text3,'string','Mouse up!');
function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double
 
 
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
 
% Hint: edit 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
相关文章
|
4月前
|
NoSQL IDE MongoDB
Studio 3T 2025.11 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.11 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
227 3
|
12天前
|
NoSQL IDE MongoDB
Studio 3T 2025.17 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.17 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
79 1
Studio 3T 2025.17 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
6月前
|
安全 数据安全/隐私保护 Windows
如何在Windows 10系统中查看已连接WiFi密码-亲测可用-优雅草卓伊凡
如何在Windows 10系统中查看已连接WiFi密码-亲测可用-优雅草卓伊凡
271 15
如何在Windows 10系统中查看已连接WiFi密码-亲测可用-优雅草卓伊凡
|
6月前
|
关系型数据库 虚拟化 UED
Omnissa Horizon Windows OS Optimization Tool 2503 - Windows 系统映像优化工具
Omnissa Horizon Windows OS Optimization Tool 2503 - Windows 系统映像优化工具
225 7
Omnissa Horizon Windows OS Optimization Tool 2503 - Windows 系统映像优化工具
|
4月前
|
NoSQL IDE MongoDB
Studio 3T 2025.10 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.10 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
292 21
Studio 3T 2025.10 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
2月前
|
Ubuntu Linux Windows
windows11系统安装ubuntu系统详细步骤
安装后,您可以直接从商店启动应用程序来源
461 0
|
4月前
|
Ubuntu Linux 数据安全/隐私保护
Windows中安装WSL 2和Ubuntu系统的教程
回看这一路,有趣吧?你已经跨界成为了一个Windows和Linux的桥梁。期待在代码的世界里,把一切玩得风生水起!
209 13
|
3月前
|
持续交付 Windows
如何使用Sysprep准备Windows系统并使用自动应答
通过Sysprep准备Windows系统,可实现SID重置与系统定制。进入Sysprep后,可安装软件、设置默认桌面文件,并使用Windows SIM创建应答文件以实现自动化部署。适用于系统克隆与批量部署场景。
|
4月前
|
数据安全/隐私保护
相控阵雷达电特性matlab模拟与仿真,带GUI界面,对比有限扫描阵,稀疏阵,多波束阵,共形阵等
本课题基于MATLAB2022a实现相控阵雷达天线电特性仿真,含GUI界面,对比有限扫描阵、稀疏阵、多波束阵及共形阵等不同类型天线的性能。相控阵雷达通过控制辐射单元的相位和幅度实现波束快速扫描与指向,广泛应用于军事和民用领域。系统具备高分辨率、多功能、抗干扰强等特点。仿真结果完整无水印,核心程序涵盖多种阵列模型,展示不同阵列的电特性和应用场景,为相控阵天线研究提供参考。
|
4月前
|
算法 安全 数据安全/隐私保护
基于AES的图像加解密算法matlab仿真,带GUI界面
本程序基于AES算法实现图像的加解密功能,并提供MATLAB GUI界面操作,支持加密与解密。运行环境为MATLAB 2022A,测试结果无水印。核心代码通过按钮回调函数完成AES加密与解密流程,包括字节替换、行移位、列混淆及密钥加等步骤。解密过程为加密逆向操作,确保数据安全性与完整性。完整程序结合128位块加密与可选密钥长度,适用于图像信息安全场景。

热门文章

最新文章