How to convert IPictureDisp to System.Drawing.Image

后端 未结 5 466
刺人心
刺人心 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:08

    Function GetImage(MyIPicture As stdole.IPictureDisp) As Drawing.Image
        If CType(MyIPicture.Type, Integer) <> 1 then Throw New ArgumentException("Image not supported")
        Return Drawing.Image.FromHbitmap(MyIPicture.Handle, MyIPicture.hPal)
    End Function
    

    Inspired from this post in the MSDN Forum. No idea why the CType(MyIPicture.Type, Integer) = 1 is required, but it works..

提交回复
热议问题