zoukankan      html  css  js  c++  java
  • 如何保存MATLAB GUI界面中的图片

    如何保存MATLAB GUI界面中的图片

    csuzhangyang@gmail.com 有任何问题,接受反馈。

    代码来源自网络,作者未知,侵删。

    原生支持png,bmp,jpg格式。另外自行添加了清晰度比较高的eps格式(荐)。

    新建一个按钮,按钮的代码如下。

    其中第二行的new_axes=copyobj(handles.axes1,new_f_handle)的handles.axes1意思是保存的是axes1中的图,以此类推。

    function pushbutton19_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton19 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    
    % 以下内容拷贝到按钮函数下。
        new_f_handle=figure('visible','off'); %新建一个不可见的figure
        new_axes=copyobj(handles.axes1,new_f_handle); %axes1是GUI界面内要保存图线的Tag,将其copy到不可见的figure中
        set(new_axes,'Units','normalized','Position',[0.1 0.1 0.8 0.8]);%将图线缩放
        [filename pathname fileindex]=uiputfile({'*.png';'*.bmp';'*.jpg';'*.eps';},'图片保存为');
        if  filename~=0%未点“取消”按钮或未关闭
            file=strcat(pathname,filename);
            switch fileindex %根据不同的选择保存为不同的类型        
                case 1
                    print(new_f_handle,'-dpng',file);% print(new_f_handle,'-dpng',filename);效果一样,将图像打印到指定文件中
                    fprintf('>>已保存到:%s
    ',file);
                case 2
                    print(new_f_handle,'-dbmp',file);
                    fprintf('>>已保存到:%s
    ',file);
                case 3
                    print(new_f_handle,'-djpg',file);
                    fprintf('>>已保存到:%s
    ',file);
                case 4
                    print(new_f_handle,'-depsc',file);
                    fprintf('>>已保存到:%s
    ',file);
            end 
            msgbox('          图线已成功保存!','完成!');
        end
    
  • 相关阅读:
    Qt高级编码约定
    QTextCodec::codecForLocale
    无边框窗口拖动代码
    QString QByteArray char 之间的转换
    Qt 程序发布指南
    qt demo pro
    snort vtun performance on vm
    xhEditor用法
    MVC控制器使用总结
    第七章 模态框
  • 原文地址:https://www.cnblogs.com/MagicConch/p/12179172.html
Copyright © 2011-2022 走看看