3

I am trying to save all the GUI while it is running using a button (based App designer). I used gca and as expected it only save the axes (using gcf result a white image), any idea how to solve it? and how I block Figure 1 from popping up?

code:

function saveGUIButtonPushed(app, event)
        guiImage = gca;
        exportgraphics(guiImage,'E:/screenExportgraphics.tif','Resolution',500)
        disp('done');
    end
RF1991
  • 2,037
  • 4
  • 8
  • 17
hs100
  • 486
  • 6
  • 20

3 Answers3

2

I do not deserve the credit as it is an answer from MATLAB Answers https://www.mathworks.com/matlabcentral/answers/410919-capturing-and-saving-an-image-of-a-running-using-code-in-matlab-s-appdesigner

Code:

            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)

It is a capture screen option that works very well, just maximize your windows.

JohnSal
  • 378
  • 3
  • 11
0

You Can Save and Load Your File Using Following Steps :

  1. Save the value in a CloseRequestFcn callback function for your app to a MAT. link to Matlab Documentation is available here.
  2. In the app's StartupFcn callback function, load the value from the MAT file and set the numeric field with this value. The documentation for App Designer's startup callback function can be found at the following link: https://www.mathworks.com/help/matlab/creating_guis/app-designer-startup-function.html
RAHIL SHA
  • 5
  • 2
0

To Convert your Matlab file you have to load data from .mat into Matlab and then you can convert it into .tif file.

let data be your matrix and xmin, xmax, ymin, ymax be minimum and maximum longitudes and latitudes respectively. You can convert this data into .tif file using:

% 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)

This should solve your problem.

RAHIL SHA
  • 5
  • 2