從COM庫(Microsoft Office Document Imaging aka MODI)我收到一個圖像作爲IPictureDisp,我想將其轉換爲System.Drawing.Image對象。如何將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中。我錯過了什麼嗎?
IPictureDispToImage()應該位於Support命名空間中嗎?但是,我得到相同的NotImplementedException。 – 2009-01-22 13:03:49