| Description |
ScreenCapture gets a screen-capture of any Matlab GUI handle (including desktop, figure, axes, image, or uicontrol), or a specified area rectangle located relative to the specified handle.
Screen area capture is possible by specifying the root (desktop) handle (=0).
The output can be either to an image file or to a Matlab matrix (useful for displaying via imshow() or for further processing), or to the system clipboard.
This utility also enables adding a toolbar button for easy interactive screen-capture.
Syntax:
imageData = screencapture(handle, position, target, 'PropName',PropValue, ...)
Input Parameters:
handle - optional handle to be used for screen-capture origin.
If empty/unsupplied then current figure (gcf) will be used.
position - optional position array in pixels: [x,y,width,height].
If empty/unsupplied then the handle's position vector will be used.
If both handle and position are empty/unsupplied then the position
will be retrieved via interactive mouse-selection.
If handle is an image, then position is in data (not pixel) units, so the
captured region remains the same after figure/axes resize (like imcrop)
target - optional filename for storing the screen-capture, or the 'clipboard' string.
If empty/unsupplied then no output to file will be done.
The file format will be determined from its extension (JPG/PNG/...).
Supported formats are those supported by the imwrite function.
If neither target nor imageData were specified, the user will be asked to
interactively specify the output file.
'PropName',PropValue -
optional list of property pairs
e.g., screencapture('target','sc.png','pos',[10,20,30,40],'handle',gca)
PropNames may be abbreviated and are case-insensitive.
PropNames may also be given in whichever order.
Supported PropNames are:
- 'handle' (default: gcf handle)
- 'position' (default: gcf position array)
- 'target' (default: '')
- 'toolbar' (figure handle; default: gcf)
this adds a screen-capture button to the figure's toolbar
If this parameter is specified, then no screen-capture
will take place and the returned imageData will be [].
Output parameters:
imageData - image data in a format acceptable by the imshow function.
If neither filename nor imageData were specified,
the user will be asked to interactively specify the output file.
Examples:
imageData = screencapture; % interactively select screen-capture rectangle
imageData = screencapture(hListbox); % capture image of a uicontrol
imageData = screencapture(0, [20,30,40,50]); % select a small desktop region
imageData = screencapture(gcf,[20,30,40,50]); % select a small figure region
imageData = screencapture(gca,[10,20,30,40]); % select a small axes region
imshow(imageData); % display the captured image in a matlab figure
imwrite(imageData,'myImage.png'); % save the captured image to file
screencapture(gcf,[],'myFigure.jpg'); % capture the entire figure into file
screencapture('handle',gcf,'target','myFigure.jpg'); % same as previous
screencapture('handle',gcf,'target','clipboard'); % copy to system clipboard
screencapture('toolbar',gcf); % adds a screen-capture button to gcf's toolbar
screencapture('toolbar',[],'target','sc.bmp'); % same with default output filename
Technical description:
http://UndocumentedMatlab.com/blog/screencapture-utility/
Bugs and suggestions:
Please send to Yair Altman (altmany at gmail dot com) |