【问题标题】:Convert System.Drawing.Bitmap to stdole.StdPicture将 System.Drawing.Bitmap 转换为 stdole.StdPicture
【发布时间】:2011-05-24 12:24:19
【问题描述】:

我目前有一个 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

那么用什么代替呢?我还没有找到其他解决方案...

【问题讨论】:

    标签: c# interop compatibility ole


    【解决方案1】:

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

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

    【讨论】:

    • 您可以在复制上述内容的原始帖子中找到更多详细信息:blogs.msdn.microsoft.com/andreww/2007/07/30/…
    • 对于那些想知道什么是“stdole”的人:您可以在 Visual Studio 解决方案资源管理器中找到它 -> 参考 -> 添加参考 -> .NET -> stdole
    【解决方案2】:

    如果您在 Google 上搜索 [convert .net image to ole picture],您会发现很多关于另一种方式(即将 ole 图片转换为图像)的讨论,以及很多建议说,实际上,“不要试图在 .NET 中使用 ole 图片”。我同意。几年前我走上了这条路,并决定我真的不需要那么糟糕的 OLE 图片。

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

    【讨论】:

    • 似乎很多人需要在loadImage的回调中做这个来自定义ribbon按钮图片。回调的签名是Public Function OnLoadImage(imageId As String) As IPictureDisp你有什么解决方法的建议吗?
    猜你喜欢
    • 2019-10-21
    • 2010-11-15
    • 2010-12-03
    • 2011-08-07
    • 2022-01-16
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多