How to convert IPictureDisp to System.Drawing.Image

后端 未结 5 468
刺人心
刺人心 2021-01-21 00:38

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.

Wh

5条回答
  •  野的像风
    2021-01-21 01:01

    Microsoft.VisualBasic.Compatibility.VB6.Support.IPictureDispToImage is not guaranteed to always be included in future updates. So... taking the example from http://support.microsoft.com/kb/555417 I came up with the following

    Example

    Public Class ImageToPictureDispConverter

    Inherits System.Windows.Forms.AxHost
    
    Public Sub New()
        MyBase.New("{63109182-966B-4e3c-A8B2-8BC4A88D221C}")
    End Sub
    
    Public Function GetImageFromIPictureDisp(ByVal objImage As stdole.IPictureDisp) As System.Drawing.Image
        Dim objPicture As System.Drawing.Image
        objPicture = CType(MyBase.GetPictureFromIPicture(objImage), System.Drawing.Image)
    
        Return objPicture
    End Function
    

    End Class

    I see in your constructor that you pass an empty string. I ended up having to pass the following string "{63109182-966B-4e3c-A8B2-8BC4A88D221C}". If I passed an empty string I received a system.formatexception error. It looks like you have everything I have except for this string in your call to base.

    Hope this helps.

提交回复
热议问题