如何保存应用程序设计GUI-MATLAB



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

代码:

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

我不配得到这个学分,因为这是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)

这是一个非常好的捕获屏幕选项,只需最大化您的窗口。

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

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

要转换Matlab文件,必须将.mat中的数据加载到Matlab中,然后才能将其转换为.tif文件。

让data是你的矩阵,xminxmaxyminimax分别是最小和最大经度和纬度。您可以将此数据转换为.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)

这应该能解决你的问题

最新更新