MATLAB Function Reference
getframe

Get movie frame

Syntax

• ```F = getframe
F = getframe(h)
F = getframe(h,rect)
[X,Map] = getframe(...)
```

Description

```getframe ``` returns a movie frame. The frame is a snapshot (pixmap) of the current axes or figure.

```F = getframe ``` gets a frame from the current axes.

```F = getframe(h) ``` gets a frame from the figure or axes identified by the handle `h`.

```F = getframe(h,rect) ``` specifies a rectangular area from which to copy the pixmap. `rect` is relative to the lower-left corner of the figure or axes `h`, in pixel units. `rect` is a four-element vector in the form `[left bottom width height]`, where `width` and `height` define the dimensions of the rectangle.

```F = getframe(...) ``` returns a movie frame, which is a structure having two fields:

• `cdata` - The image data stored as a matrix of uint8 values. The dimensions of `F.cdata` are height-by-width-by-3.
• `colormap` - The colormap stored as an n-by-3 matrix of doubles. `F.colormap` is empty on true color systems.

To capture an image, use this approach:

• ```F = getframe(gcf);
image(F.cdata)
colormap(F.colormap)
```

```[X,Map] = getframe(...) ``` returns the frame as an indexed image matrix `X` and a colormap `Map`. This version is obsolete and is supported only for compatibility with earlier version of MATLAB. Since indexed images cannot always capture true color displays, you should use the single output argument form of `getframe`. To write code that is compatible with earlier version of MATLAB and that can take advantage of true color support, use the following approach:

• ```F = getframe(gcf);
[X,Map] = frame2im(f);
imshow(X,Map)
```

Remarks

Usually, `getframe` is used in a `for` loop to assemble an array of movie frames for playback using `movie`. For example,

• ```for j = 1:n
```plotting commands
```    F(j) = getframe;
end
movie(F)
```

To create movies that are compatible with earlier versions of MATLAB (before Release 11/MATLAB 5.3) use this approach:

• ```M = moviein(n);
for j = 1:n
```plotting commands
```    M(:,j) = getframe;
end
movie(M)
```

Capture Regions

Note that `F = getframe;` returns the contents of the current axes, exclusive of the axis labels, title, or tick labels. `F = getframe(``gcf``);` captures the entire interior of the current figure window. To capture the figure window menu, use the form `F = getframe(h,rect)` with a rectangle sized to include the menu.

Examples

Make the `peaks` function vibrate.

• ``````Z = peaks; surf(Z)
````axis` tight
set(gca,'nextplot','replacechildren');
for j = 1:20
surf(sin(2*pi*j/20)*Z,Z)
F(j) = getframe;
end
movie(F,20) % Play the movie twenty times
```

`frame2im`, `image`, `im2frame`, `movie`