Appdesigner Print Screen Problem - Appdesigner is a disappointment!
25 views (last 30 days)
I am transitioing to the use of appdesigner, but it seems to suck at printing interface with figures and tables all together.
I saw a post where someone suggested to create a local handle to plot and save a figure, but I am trying to plot everything on the interface including figures, tables, buttons etc.
I tried using print command that I was using in "guide" that was warking perfectly there, but obviously it doesn't work in app designer. Did they purposely make the appdesigner horrible with basic tools like print, save, saveas, rotate, etc... missing so that nobody should use the appdesigner? If I am creating an app, I d want to print it in a way to store it, right?!!! Anyways, this is kind of disappointing. Is there any easy way around this, anybody knows?
I don't want to use an external screen snipping tool b/c the quality of those are not as good and not as professional.
I appreciate any comments!
This is the error I get with "print" command:
Error using print (line 79)
Functionality not supported with figures created with the uifigure function. For more information, see Graphics Support in App Designer.
Error in app2/Button5Pushed (line 82)
print -clipboard -dmeta; % copy the figure to clipboard
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.
Adam Danz on 23 Apr 2020
Edited: Adam Danz on 17 Nov 2020
There are two new functions as of r2020a that address this problem,
They are still a little buggy but I'm sure improvements will come with future releases.
Also take note of copyUIAxes from the file exchange that copies a UIAxes (not an entire figure). I'd first try to use the two functions above, though.
Also see this a Community Highlight to learn about exportapp and getframe with Apps in Matlab r2020b+.
Allen on 16 Nov 2020
I have been trying to find a solution to the same issue. I was able to save my figure to an image file perfectly in GUIDE, which served to screen capture the figure and all of its contents. As Adam states, App Designer does not yet have the functionality to do this in a simple fashion (shame). I have tried to use the new exportgraphics function, but unsuccessfully. However, I have had moderate success by using the following code that uses undocumented features in MATLAB. Its main issue is when using various montitor sizes, configurations, and/or resolutions.
% This option is necessary since saveas() does not work with App Designer's UIFigures.
robot = java.awt.Robot();
temp = app.fig_SpeedTrapTool.Position; % returns position as [left bottom width height]
allMonPos = get(0,"MonitorPositions");
curMon = find(temp(1)<(allMonPos(:,1)+allMonPos(:,3)),1,"first");
curMonHeight = allMonPos(curMon,4)+1;
pos = [temp(1),curMonHeight-(temp(2)+temp(4)),temp(3)-1,temp(4)]; % [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,)';
hImg = imshow(imgData);
If you or someone else has been able to come up with a better solution, I would be excited if able to share. Hopefully, Mathworks has plans to improve on the exportgraphics function in a near future upgrade.