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
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.