如何将IPictureDisp转换为System

如何将IPictureDisp转换为System

本文介绍了如何将IPictureDisp转换为System.Drawing.Image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从COM库(Microsoft Office Document Imaging,也称为MODI)中,我收到了要转换为System.Drawing.Image对象的IPictureDisp图像.

From a COM library (Microsoft Office Document Imaging aka MODI) I receive an image as an IPictureDisp which I would like to convert to a System.Drawing.Image object.

做到这一点的最佳方法是什么?

What would be the best way to do that?

当前我正在使用下面的代码,但是会引发NotImplementedException.

Currently I'm using the code below, which however throws an NotImplementedException.

internal sealed class IPictureDispHost : AxHost
{
    /// <summary>
    /// Default Constructor, required by the framework.
    /// </summary>
    private IPictureDispHost() : base(string.Empty) { }
    /// <summary>
    /// Convert the image to an ipicturedisp.
    /// </summary>
    /// <param name="image">The image instance</param>
    /// <returns>The picture dispatch object.</returns>
    public new static object GetIPictureDispFromPicture(Image image)
    {
        return AxHost.GetIPictureDispFromPicture(image);
    }
    /// <summary>
    /// Convert the dispatch interface into an image object.
    /// </summary>
    /// <param name="picture">The picture interface</param>
    /// <returns>An image instance.</returns>
    public new static Image GetPictureFromIPicture(object picture)
    {
        return AxHost.GetPictureFromIPicture(picture);
    }
}

...

// somewhere later the conversion gets called
Image image = IPictureDispHost.GetPictureFromIPicture(picture);

这是异常堆栈跟踪:

System.NotImplementedException: The method or operation is not implemented.
   at System.Windows.Forms.UnsafeNativeMethods.IPicture.GetHandle()
   at System.Windows.Forms.AxHost.GetPictureFromIPicture(Object picture)
   at DocumentViewer.IPictureDispHost.GetPictureFromIPicture(Object picture)

我在项目中引用了stdole,System.Windows.Forms和System.Drawing.我想念什么吗?

I have references to stdole, System.Windows.Forms and System.Drawing in my project. Am I missing something?

推荐答案

从Microsoft Office Document Imaging COM组件获得的图片似乎不是有效的IPictureDisp对象,并且似乎无法对其进行转换.

As it seems the picture obtained from the Microsoft Office Document Imaging COM components is not a valid IPictureDisp object and there seems no way to convert it.

这篇关于如何将IPictureDisp转换为System.Drawing.Image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 22:09