调用 Icon.ToBitmap() 后处理 Icon 是否安全?
调用System.Drawing.Icon.ToBitmap()
创建图像后,处理原始Icon
是否安全?
After calling System.Drawing.Icon.ToBitmap()
to create an image, is it safe to dispose the original Icon
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该方法将
Icon
转换为新的Bitmap
对象,因此Bitmap
不会引用Icon
>。所以是的,处理
Icon
是安全的。The method converts an
Icon
to a newBitmap
object, so there will be no reference from theBitmap
to theIcon
.So yes, it is safe to dispose the
Icon
.是的。 Icon.ToBitmap 将 Icon 绘制到新的 Bitmap 对象,因此之后可以安全地处理它。
编辑:
查看 Reflector 中的 Icon.ToBitmap() 方法很有趣。 我期望它是一个简单的 Graphics.DrawImage 或 Graphics.DrawIcon 调用,但它比这更复杂。 只要有可能,该函数就会对图标图像数据进行内存复制,但如果无法执行复制,它将恢复为 Graphics.DrawImage 或 Graphics.DrawIcon 调用。 内存复制速度要快得多,这显然是原因,但这使得代码更难阅读。
Yes. Icon.ToBitmap draws the Icon to a new Bitmap object so it is safe to dispose it afterwards.
Edit:
Looking at the Icon.ToBitmap() method in Reflector was interesting. I expected it to be a simple Graphics.DrawImage or Graphics.DrawIcon call but it is more involved than that. As long as it is possible the function will do a memory copy of the icon image data instead, but it will revert to a Graphics.DrawImage or Graphics.DrawIcon call if it cannot perform the copy. The memory copy is much faster so that is obviously the reason, but this makes the code much harder to read.
是的。
如果您不再需要该图标,并且将位图存储在某处,那就没问题了。
Yes.
If you don't need the icon any more, and have the bitmap stored somewhere, you're fine.