MFC and WPF interop: render a CDC* to WPF

  • Thread starter Thread starter bonk
  • Start date Start date
B

bonk

Within an MFC application that also has some WPF content embedded into
the UI (via HWndSource) I have a pointer to a CDC wich contains some
custom GDI drawing. So basically it is a piece of memeory with a bitmap.
How can I get this to be displayed in WPF (within the HWndSource) ? I
guess it all boils down to how I could convert to that "unmanaged"
bitmap memory to something WPF (.NET) understands without having to
actually create a Bitmap File on Disk from that CDC.

Any workaround is welcome :)
 
I haven't done this with MFC and .NET, but i worked around a similar problem
with 2 other environments (native C++ and LabVIEW).

basically, allocate a new .NET bitmap object, with a predefined size (the
size of your bitmap).
make sure that the pixel format (nb bits per pixel etc) is the same as your
original bitmap.
try to get a pointer to the new (blank) bitmap and pin it into memory.
copy the original bitmap data into the pinned bitmap pointer.

after that you can use the new .NET bitmap object any way you choose.
this is not the cleanest solution maybe, but the only thing i could come up
with.

kind regards,
Bruno.
 
Back
Top