Graphics.Save 与 Graphics.BeginContainer

发布于 2024-08-02 06:01:21 字数 78 浏览 5 评论 0原文

Graphics.SaveGraphics.BeginContainer 有何不同?

How is Graphics.Save different from Graphics.BeginContainer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

七颜 2024-08-09 06:01:21

请查看此处

文档中没有
区分调用
BeginContainer/EndContainer 和调用
到 Graphics.Save 和 GraphicsRestore。
此外,还有一些错误
文档。 [例如,
GraphicsState 断言不正确
由 BeginContainer 使用]

在我的使用中,BeginContainer/EndContainer 似乎
保存并恢复当前
转换。它实际上并没有保存
剪切区域为
文档断言,它可能不是
将任何其他属性保存在
图形对象。

通过保存/恢复,我实际上能够保存/恢复剪辑
区域、电流变换等
设置。看来是,如果不是的话
完整的,比
容器功能。因此,我
怀疑性能/完整性
与两个不同的权衡
方法。

我也怀疑文档中的说法是否正确
GraphicsState 对象(由
Save)按原样存储在堆栈中
GraphicsContainer 对象(由
开始容器)。我怀疑
GraphicsState 甚至可能无法放置
在堆栈上,但我还没有测试过这个
假设。

take a look here:

The documentation does not
differentiate between calls to
BeginContainer/EndContainer and calls
to Graphics.Save and GraphicsRestore.
In addition, there are a few errors in
the documentation. [e.g.,
GraphicsState is incorrectly asserted
to be used by BeginContainer]

In my use, BeginContainer/EndContainer appears to
save and restore the current
transform. It does not actually save
the clipping region as the
documentation asserts, and it may not
save any of the other properties in
the graphics objects.

With Save/Restore, I was actually able to save/restore the clipping
region, current transform, and other
settings. It appears to be, if not
complete, more "complete" than the
container functions. Therefore, I
suspect a performance/completeness
tradeoff with the two different
methods.

I also doubt whether the documentation is correct in stating
that GraphicsState objects (used by
Save) are stored in the stack as are
GraphicsContainer objects (used by
BeginContainer). I suspect that
GraphicsState may not even be placed
on a stack, but I have not tested this
hypothesis.

踏雪无痕 2024-08-09 06:01:21

也许我可以从MSDN的一些例子给出解释。我的MSDN版本是Visual Studio 2008 SP1。在MSDN的编辑中输入关键字“Nested Graphics Containers”就可以找到示例。

其解释如下:

如前面两个示例所示,变换和剪切区域在嵌套容器中是累积的。如果您设置容器和 Graphics 对象的世界变换,则这两种变换都将应用于从容器内部绘制的项目。首先应用容器的变换,然后应用 Graphics 对象的变换。如果设置容器和 Graphics 对象的剪切区域,则从容器内部绘制的项目将被两个剪切区域的交集剪切。

从上面复制的内容来看,关键词是“累计”和“交集”。因此,我认为这可以成为理解BeginContainer函数的一种方式。

完整的 MSDN 文章位于此处。

Maybe I can give a explanation from some examples of MSDN. The version of my MSDN is Visual Studio 2008 SP1. And the examples can be found when you enter the keyword "Nested Graphics Containers" in the edit of MSDN.

And its explanation is below:

As the two preceding examples show, transformations and clipping regions are cumulative in nested containers. If you set the world transformations of the container and the Graphics object, both transformations will apply to items drawn from inside the container. The transformation of the container will be applied first, and the transformation of the Graphics object will be applied second. If you set the clipping regions of the container and the Graphics object, items drawn from inside the container will be clipped by the intersection of the two clipping regions.

From the content copied above, the keywords are "cumulative" and "intersection". Therefore, I think it can be a way to understand the BeginContainer function.

Full MSDN article available here.

哆啦不做梦 2024-08-09 06:01:21

图形.保存方法
保存此 Graphics 的当前状态并使用 GraphicsState 标识保存的状态。

Graphics.BeginContainer方法
使用此 Graphics 对象的当前状态保存图形容器,并打开并使用新的图形容器。

备注

调用BeginContainer方法会将信息块与调用Save方法放置在同一堆栈上。正如 Restore 调用与 Save 调用配对一样,EndContainer 方法调用与 BeginContainer 方法调用配对。

当您调用Restore方法时,在对Save方法的相应调用之后放置在堆栈上的所有信息块(通过Save方法或通过BeginContainer方法)都将从中删除堆栈。同样,当您调用 EndContainer 方法时,所有信息块(通过 Save 方法或通过 BeginContainer 方法)在对 BeginContainer 方法的相应调用将从堆栈中删除。

详情请参阅
http://msdn.microsoft.com/en-我们/library/system.drawing.graphics.save.aspx

Graphics.Save Method
Saves the current state of this Graphics and identifies the saved state with a GraphicsState.

Graphics.BeginContainer Method
Saves a graphics container with the current state of this Graphics object and opens and uses a new graphics container.

Remarks

Calls to the BeginContainer method place information blocks on the same stack as calls to the Save method. Just as a Restore call is paired with a Save call, a EndContainer method call is paired with a BeginContainer method call.

When you call the Restore method, all information blocks placed on the stack (by the Save method or by the BeginContainer method) after the corresponding call to the Save method are removed from the stack. Likewise, When you call the EndContainer method, all information blocks placed on the stack (by the Save method or by the BeginContainer method) after the corresponding call to the BeginContainer method are removed from the stack.

See details on
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.save.aspx

白云悠悠 2024-08-09 06:01:21

BeginContainer()Save() 之间的区别仅在于 BeginContainer() 将所有渲染属性重置为其默认状态。

简而言之,BeginContainer() 执行以下操作:

  • 在内部执行 Save() 以保存图形的当前状态
  • ,重置所有渲染属性(TextRenderingHint、InterpolationMode、SmoothingMode 等),我们不知道确切的属性列表)以默认其状态。

您可以在 文档的备注部分找到有关它的提示

BeginContainer方法建立的图形状态包括
默认图形状态的渲染质量;任何
调用该方法时存在的渲染质量状态更改是
重置为默认值。

PS:这不是完整的答案,因为我们仍然不知道重置为默认状态的属性的完整列表,不幸的是文档对此只字未提。

The difference between BeginContainer() and Save() is only that BeginContainer() resets all rendering properties to their default state.

So in brief BeginContainer() does following:

  • executes Save() internally to save the current state of graphics
  • reset all rendering properties (TextRenderingHint, InterpolationMode, SmoothingMode and so on, we don't know exact list of properties) to default their state.

You can find hint about it in the remarks section of documentation:

The graphics state established by the BeginContainer method includes
the rendering qualities of the default graphics state; any
rendering-quality state changes existing when the method is called are
reset to the default values.

P.S.: This is not complete answer because we still don't know the full list of properties that are reset to default state, unfortunately documentation say nothing about it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文