COM StdPicture-to-Image conversion

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

We're authoring a VS 2005 app that includes several EXE's and DLL's and also
uses a COM component (a customer requirement). The COM component provides a
graphic image to be used by the .NET app; the graphic is supplied as a
"StdPicture" (AKA, IPictureDisp).

How can I convert this to a .NET Image? A search of the object browser
shows:

protected static System.Drawing.Image GetPictureFromIPictureDisp(object
picture)
Member of System.Windows.Forms.AxHost

and in VB.NET
Microsoft.VisualBasic.Compatibility.VB6.IPictureDispToImage

Is there any other, more workable way to accomplish this conversion?

TIA ...
 
Is there any other, more workable way to accomplish this conversion?

What do you mean by "more workable"? What's wrong with the method you
listed?


Mattias
 
Hi Mattias,

Thanks for responding.

Of these two methods, using the AxHost method would appear to be a kludge -
or at least inappropriate - for a library (DLL), as I think it would require
a control on a windows form.

And using the VB6 compatibility layer of VB.NET just seems kind-of ...
silly? ... for a C# library.

I'm sure I must be missing something ... but I just don't see what that is!

--Mark
 
You don't need a control on a form, you just need a class that derives from
AxHost so that you can call the appropriate protected static methods. This
will create a dependency on System.Windows.Forms.dll.

The alternative is to create a managed definition for IPictureDisp so that
you can retrieve the GDI handle of the picture object. You can then use this
handle to create an appropriate GDI+ image, e.g. Image.FromHbitmap,
Icon.FromHandle, etc.
 
Back
Top