Screenshot entire window in AppDesigner

Hello everybody,
I'm currently building an app using AppDesigner. I want to implement a button, which captures a screenshot from the entire app after it's been pressed. So that I can compare different sets of data afterwards with just a quick look on their screenshots.
Unfortunately I cannot come up with an idea on how to make Matlab screenshot my entire app window. In a regular Matlab script I use the ScreenCapture function from FileExchange, but this seems not to work within AppDesigner.
imageData = screencapture(gcf,[],'myFigure.jpg');
Any suggestions on how to do this?
Since I have multiple tabs it would be ideal to come up with an idea on how to "screenshot" every tab with just one press of a button.
Cheers, Christian

Answers (1)

Starting in Matlab r2020b, you can take snapshots of an app / uifigure using the functions below.
See demos:

7 Comments

What if I am using Matlab 2018 and I have the same problem?
@Shahar Wollmark maybe try saveas() or print().
Adam Danz
Adam Danz on 23 Mar 2022
Edited: Adam Danz on 23 Mar 2022
Unforunately other methods such as print or saveas are not supported for UIFigures in R2018b so I would recommend updating to a release >=20b to save app figures or use a 3rd party screen shot software.
IoP
IoP on 17 May 2023
Moved: Adam Danz on 18 May 2023
Can you copy to clipboard also somehow?
Generally, copygraphics can be used to copy graphics content from a figure to the clipboard. However, ui controls are not considered to be graphics objects so only graphics objects such as axes will be copied to the clipboard. If your app has no graphics objects, you'll get an error. If your app has a mix of graphics objects and non-graphics objects, you'll get a warning.
The print('-clipboard',clipboardformat) options have similar limitations.
Dorian
Dorian on 8 Mar 2024
Edited: Dorian on 8 Mar 2024
Hello,
I am using the exportapp function with Matlab R2023a and screenshoting my app does not work while having a very simple class :
function JourButtonPushed(app, event)
exportapp(app,'file.png');
end
It says "Specified handle is not valid for export." and there are no mentions of being able to capture the app itself in the help pages for exportapp or getframe. I have also directly tried the example shown in the link you sent, and app.MyApp (after changing MyApp to my actual app name) still claims that "MyApp" is an undefined class, property or field. Am I doing something wrong or were there changes in the most recent versions that hindered the compatibility ? While unrelated I have also experienced such issues with some app components not posessing an Alpha variable for transparency despite older posts being able to handle the transparency of the same components this way, so this is why I think the newer versions may have changed this aswell ?
@Dorian, the first argument needs to be a figure handle.
function JourButtonPushed(app, event)
exportapp(app.UIFigure,'file.png');
end

Sign in to comment.

Categories

Find more on Develop Apps Programmatically in Help Center and File Exchange

Asked:

on 20 May 2019

Commented:

on 15 Mar 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!