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

时间:2011-05-24 12:24:20

标签: c# interop compatibility ole

我目前有一个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位进程内受支持。{{3 }}

那么使用什么呢?我找不到另一个解决方案......

2 个答案:

答案 0 :(得分:6)

取自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);
   }
} 

答案 1 :(得分:0)

如果您在Google上搜索[将.net图片转换为图片],您会发现很多关于其他方式的讨论(例如将图片转换为图片),以及很多建议实际上,“不要试图在.NET中使用ole图片”。我同意。几年前我走了那条路,决定我不太需要那张OLE画面。

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