Reputation: 13632
We’re creating a web application that will display contour areas as bitmaps in a browser interface.
We already have an extensive Delphi library that can generate contours, and can draw them onto a TCanvas. We’d like to be able to re-use that code as much as possible.
So we’ve created a COM object in Delphi, and use that to generate contours. I’ve added a reference to that COM object in my ASP.Net project, so I can access it from .Net code. So far, this seems to work out nicely.
The problem I’m running into now, is getting the generated TBitmap to the ASP.Net side of things, as fast as possible.
There are some scenarios I can think of, but I’m running into problems on each of them:
Saving the bitmap to stream (as PNG), and return an IStream
interface. Problem is that the COM object wizard doesn’t seem to accept IStream
as return value for a function. Also, I don’t know if .Net will know what to do with it, but I hope the Interop wrapper will take care of that.
Saving the bitmap to stream (as PNG), and return a byte array. What return type should I use then? I’m guessing SAFEARRAY(byte)
(the wizard accepts that, at least), but a) how do I create a SAFEARRAY on the Delphi side, and b) how do I read that in .Net?
Somehow converting the TBitmap
to an IPicture
interface, and returning that. IPicture, at least, seems to be supported by the COM object wizard. Here I don’t really know how to convert the TBitmap to an IPicture (except saving it to stream, and creating an IPicture from that stream, which seems a bit silly since the .Net code will have to stream it out to the browser anyway). Again, I have no idea how .Net will handle the IPicture
, though I hope it will map it to a regular Image
object, which can then be written out via the Response
object.
So my question is: what would be the best way to go forward, in terms of performance, and how to solve the problems indicated?
Upvotes: 2
Views: 886
Reputation: 613432
I'd pass an HBITMAP between native and managed worlds.
TBitmap
by calling ReleaseHandle
.Bitmap
by calling Image.FromHbitmap()
.Upvotes: 4
Reputation: 24141
You could write a Delphi COM object, which owns the bitmap and can return a bitmap handle. You can get this handle from TBitmap and cast it to OLE_HANDLE. As long as you hold a reference to the COM object, the bitmap would be valid.
Upvotes: 2