gpt4 book ai didi

c# - 如何将 IPictureDisp 转换为 System.Drawing.Image

转载 作者:行者123 更新时间:2023-12-01 22:04:35 25 4
gpt4 key购买 nike

从 COM 库(Microsoft Office Document Imaging 又名 MODI),我收到一个 IPictureDisp 形式的图像,我想将其转换为 System.Drawing.Image 对象。

最好的方法是什么?

目前我正在使用下面的代码,但它会抛出 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。我错过了什么吗?

最佳答案

看看这个 article .

它描述了三种不同的选项,只需选择您认为最简单或“最干净”的选项(包括您声称不适合您的选项)。

<小时/>

Olivier Jacot-Descombe:上面的链接已损坏。我已添加来自互联网文件馆的相应链接 WayBackMachine :

Converting between IPictureDisp and System.Drawing.Image (MSDN 博客 > Andrew Whitechapel)。

关于c# - 如何将 IPictureDisp 转换为 System.Drawing.Image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/468972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com