Why does turning the visibility of a figure to "off" slow things down?

15 次查看(过去 30 天)
I have an application where turning the visibility of the figure off actually quadruples the run time of my program. I do a lot of axis and lighting manipulations between grabbing the screen.
Here is brief example that leads to a roughly 10% increase in time:
%%->> Visible ON<<-
tic
h = figure('Visible', 'On');
surf(peaks);
light;
axis([10 40 10 40 -5 5]);
h.Color = 'r';
view(45,45);
data = getframe();
toc
%%->>Visible OFF<<-
tic
h = figure('Visible', 'Off');
surf(peaks);
light;
axis([10 40 10 40 -5 5]);
h.Color = 'r';
view(45,45);
data = getframe();
toc
Basically, I would love an explanation as to why MATLAB acts any differently when the figure is not displayed!

回答(1 个)

Mike Garrity
Mike Garrity 2015-11-19
They actually don't do the same thing at all.
In the Visible='on' case, the pixels are already sitting in the framebuffer on the graphics card. The getframe function just fetches them.
In the Visible='off' case, there is no framebuffer and the graphics haven't already been drawn. So the getframe command basically starts a print job. Printing is nearly as tightly optimized as on screen rendering because it supports lots of additional features that you're not using here. For one thing, it needs to allocate a number of resources which are basically free when you're drawing into the framebuffer.
  2 个评论
Walter Roberson
Walter Roberson 2015-11-19
Mike, is that "is nearly" or "is not nearly" ? The "is nearly" would imply that the timing should be very close, which the rest of your discussion seems to argue otherwise.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by