Screenshot of specific window (not full screen)

3 views (last 30 days)
Hello,
is it possible to take a screenshot (I used Java commands) of only a specific Window (not the entire screen) ? - for instance, from the full screen below I only want to take a screenshot from the pop-up screen (GUI window)
To take a screenshot from the full window I used the following commands:
robo = java.awt.Robot;
t = java.awt.Toolkit.getDefaultToolkit();
rectangle = java.awt.Rectangle(t.getScreenSize());
image = robo.createScreenCapture(rectangle);
Thanks

Accepted Answer

Image Analyst
Image Analyst on 17 Sep 2022
Edited: Image Analyst on 17 Sep 2022
Use exportgraphics and pass it the handle of just the one figure or axes that you want.
fileName = fullfile(pwd, 'Screenshot.png')
exportgraphics(gcf, fileName); % Save current figure window.
% or
exportgraphics(gca, fileName); % Save last axes you plotted in.

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by