如何保存 App 设计器 GUI - MATLAB

How to save the App desginer GUI - MATLAB

我正在尝试使用按钮(基于应用程序设计器)在 运行 时保存所有 GUI。我使用了 gca 并且正如预期的那样它只保存轴(使用 gcf 结果是白色图像),知道如何解决它吗?以及如何阻止图 1 弹出?

代码:

function saveGUIButtonPushed(app, event)
        guiImage = gca;
        exportgraphics(guiImage,'E:/screenExportgraphics.tif','Resolution',500)
        disp('done');
    end

您可以使用以下步骤保存和加载文件:

  1. 将应用程序的 CloseRequestFcn 回调函数中的值保存到 MAT。 link Matlab 文档可用 here
  2. 在应用程序的 StartupFcn 回调函数中,从 MAT 文件加载值并使用该值设置数值字段。 App Designer 的启动回调函数的文档可以在下面link找到: https://www.mathworks.com/help/matlab/creating_guis/app-designer-startup-function.html

要转换您的 Matlab 文件,您必须将数据从 .mat 加载到 Matlab 中,然后您可以将其转换为 .tif 文件.

让数据成为你的矩阵 xmin, xmax, ymin, ymax 分别是最小和最大经度和纬度。您可以将此数据转换为 .tif 文件 使用:

% Write the data into geotiff 
R = georasterref('RasterSize',size(data),'LatitudeLimits',[ymin,ymax],'LongitudeLimits',[xmin,xmax]);
geotiffwrite('myfile.tif',data,R)
%%Read geotiff file
[A, R] = geotiffread(tiffile);
figure
mapshow(A, R)

这应该可以解决您的问题。

我不值得称赞,因为这是来自 MATLAB Answers 的答案 https://www.mathworks.com/matlabcentral/answers/410919-capturing-and-saving-an-image-of-a-running-using-code-in-matlab-s-appdesigner

代码:

            robot = java.awt.Robot();
            pos = [0 0 1680 1050]; % [left top width height]
            rect = java.awt.Rectangle(pos(1),pos(2),pos(3),pos(4));
            cap = robot.createScreenCapture(rect);
            % Convert to an RGB image
            rgb = typecast(cap.getRGB(0,0,cap.getWidth,cap.getHeight,[],0,cap.getWidth),'uint8');
            imgData = zeros(cap.getHeight,cap.getWidth,3,'uint8');
            imgData(:,:,1) = reshape(rgb(3:4:end),cap.getWidth,[])';
            imgData(:,:,2) = reshape(rgb(2:4:end),cap.getWidth,[])';
            imgData(:,:,3) = reshape(rgb(1:4:end),cap.getWidth,[])';
            % Show or save to file
            imshow(imgData)
            imwrite(imgData,'I:/screenCap.tif', 'Resolution', 500)

这是一个效果很好的截屏选项,只需最大化您的 windows。