getframe in MATLAB movie

5 views (last 30 days)
Francesco
Francesco on 2 Apr 2013
I am creating a movie from MATLAB figures. When I call getframe, it "usually" captures the plot image, but from today if there is something else active on the screen (which is normal if I continue to use the computer) it captures whatever window is active. Is there another way to grab the image of the active figure? Somebody knows what happened?
the scheme to create the movie is:
wobj = VideoWriter(); f=figure();
open(wobj);
for.....
F=getframe(gcf); writeVideo(wobj,F);
end....
close(wobj);

Answers (2)

Jan
Jan on 2 Apr 2013
GETFRAME captures the screen contents inside the figure coordinates. If another window is in the foreground, the original figure is hidden.
The print command is not limited in this way, but it does not create pixel-exact copies in consequence. If this does not bother you, print to a PNG and import the files afterwards to create the movie.

Mahdi
Mahdi on 2 Apr 2013
Just set your getframe(gcf) to whichever window you want to capture.
For example, if you want to capture the plot in figure 1, you would use
getframe(1)
and so on. gcf is basically the "handle" to the figure. Using gcf on its own just uses the active window.
  2 Comments
Mahdi
Mahdi on 2 Apr 2013
To make it more clear, look at the lines that I suggested modifying.
wobj=VideoWriter();
f=figure(1); % This line
open(wobj);
for ...
F=getframe(1) % And this line
...
Francesco
Francesco on 2 Apr 2013
I tried it but it does not work... It is a strange thing, because with the code that I wrote above, yesterday it worked today no. Thanks

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!