关于图形处理的问题
我是否需要在 OnPaint 事件中对通过 PaintEventArgs 获取的 Graphics 对象调用 Dispose() ?
Do I need to call Dispose() on a Graphics object obtained through PaintEventArgs in an OnPaint event?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,调用层(实际创建图形对象的层)负责这一点。
还要考虑一下,当链上有其他被调用者时,您将处置该对象,而他们将无法使用它。
No, the calling layer (the one who actually created the graphics object) is in charge of that.
Also think about it, when you have other callees on the chain, you will dispose the object and they won't be able to use it.
一般来说,您不应该处置作为方法参数接收的 Graphic 对象。 但是您应该处理您自己创建的 Graphics 对象(例如使用
CreateGraphics
方法)。In general, you should not dispose of Graphic objects which you receive as method parameters. But you should dispos of Graphics objects that you've created yourself (for example using the
CreateGraphics
method).