在 .NET 4.0 中将图标转换为 IPicture?
标准和(某种程度上)支持的答案之一是使用 Microsoft.VisualBasic.Compatibility 程序集中的 Support.IconToIPicture。但是,在 .NET 4.0 中,“此 API 现已过时”。
One of the standard and (somewhat) supported answers was to use Support.IconToIPicture from the Microsoft.VisualBasic.Compatibility assembly. However, in .NET 4.0, "This API is now obsolete".
Yes, there are various solutions out there, but I would think that if Microsoft was obsoleting this method, there would be another "supported" alternative.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信,这个API已经过时了,因为IPicture是一个OLE接口。通过使用它,您将进入 Microsoft 不希望您进入的非托管世界。您可以通过调用来重现该行为
IntPtr aHIcon = Icon.GetHicnFromIcon(yourIcon);
然后您需要将此句柄传递给 OleCreatePictureIndirect (代码是 C++ 语言):
唯一的困难 -- 您需要提供用于包装的 COM 互操作代码C++ 结构和函数调用。
I believe, this API is obsolete, because IPicture is an OLE interface. By working with it, you dive into the unmanaged world which Microsoft doesn't want you to. You could reproduce the behavior by calling
IntPtr aHIcon = Icon.GetHicnFromIcon(yourIcon);
Then you need to pass this handle to OleCreatePictureIndirect (the code is in C++):
The only difficulty -- you will need to provide a COM interop code for wrapping the C++ structure and function call.