tags:

views:

167

answers:

2

We have a COM object implemented with C++/ATL that includes a method which will return a DIB. We are also writing a .NET application that will use this COM object. Since we are writing both, we have the liberty of deciding how best to return this DIB from the COM object. To clarify, would it be best to return a native windows handle to a DIB or a byte array or is there some other way to easily transition a windows DIB into a .NET Image object? And, related to that question: once I have this returned DIB how can I get it into a .NET Image object?

+1  A: 

Have a look at the article DIB to System.Bitmap on CodeProject. It has the code to convert from a DIB to a Bitmap. The idea is that the DIB is represented using a IntPtr.

smink
+1  A: 

COM/OLE has a standard interface for representing graphical images called IPicture (and its scripting-friendly version IPictureDisp).

COM provides an implementation of these interfaces for you. You can get it to build one for you by calling OleCreatePictureIndirect(). You just hand it a PICTDESC structure with the graphic you have, and it gives you back an interface. You should be able to hand that interface back to the calling program. This will also make your object compatible with other COM clients like VB6.

Back in .NET land you can turn an IPicture into an Image using Microsoft.VisualBasic.Compatibility.VB6.IPictureToImage().

Tim Farley