How to get a DIB implemented in a C++/COM library into a .NET client using that COM object
Asked Answered
P

2

0

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?

Patricapatrice answered 5/11, 2008 at 17:32 Comment(0)
C
2

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().

Crampton answered 5/11, 2008 at 20:28 Comment(0)
S
1

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.

Septime answered 5/11, 2008 at 18:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.