将System.Drawing.Bitmap转换为stdole.StdPicture

我当前有一个System.Drawing.Bitmap,我需要将其转换为stdole.StdPicture。
目前我正在使用:

var pic = (stdole.StdPicture)Microsoft.VisualBasic.Compatibility.VB6.Support.ImageToIPicture (MyDLL.Properties.Resources.Img); // this is a System.Drawing.Bitmap 

但我得到一个编译器警告:

警告’Microsoft.VisualBasic.Compatibility.VB6.Support.ImageToIPicture(System.Drawing.Image)’已过时:’“Microsoft.VisualBasic.Compatibility。*类已过时,仅在32位进程中受支持.http:// go。 microsoft.com/fwlink/?linkid=160862

那么使用什么呢? 我还没找到另一个解决方案……

取自NetOffice http://netoffice.codeplex.com Office Addin示例

 public class IconConverter : System.Windows.Forms.AxHost { private IconConverter(): base(string.Empty) { } public static stdole.IPictureDisp GetIPictureDispFromImage(System.Drawing.Image image) { return (stdole.IPictureDisp)GetIPictureDispFromPicture(image); } } 

如果你在谷歌搜索[转换.net图像到ole图片],你会发现很多关于其他方式的讨论(即将图片转换为图片),以及许多建议,效果,“不要尝试在.NET中使用ole图片”。 我同意。 几年前我走了那条路,并决定我真的不需要那么糟糕的OLE画面。

我强烈建议您重新评估您对OLE图片对象的需求。 如果要将图像保存在数据库中,请将它们存储为BLOB而不是图片对象。 如果你绝对必须使用OLE图片对象,那么祝你好运。 这将非常令人沮丧。