0

I am trying to create Bitmap^ from unsigned char* databuffer. I need to do this very effective - this function called many times each second and GUI updated after it runs. My code is :

unsigned char*  databuffer = new unsigned char[_size];
System::IntPtr _intptr = System::IntPtr(databuffer);

System::Windows::Media::Imaging::BitmapSource^ b =
    System::Windows::Interop::Imaging::CreateBitmapSourceFromMemorySection(_intptr, width, height,
    System::Windows::Media::PixelFormats::Bgr32, width, 0);

When last line runs , the exception is thrown : "The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))"

Is there another way to do this ? (I tried to convert the unsigned char* first into Bitmap^ and then into BitmapSource^ but this takes too much time).

Thanks.

Matvey
  • 163
  • 2
  • 10
  • The correct tag (instead of `c++` and `command-line-interface`) for C++/CLI code is `c++-cli`. – crashmstr Jan 07 '15 at 17:46
  • 1
    Documentation is a bit clumsy, but the exception is accurate. "Section" is another word for "memory mapped file". You need to pass the handle you obtained from CreateFileMapping(). Probably not what you want. You also need to make up your mind whether you want to Bitmap or a BitmapSource. The Bitmap constructor takes a pointer and doesn't need an MMF. – Hans Passant Jan 07 '15 at 17:59
  • I want a BitmapSource. I think CreateFileMapping will also slow down the function. – Matvey Jan 08 '15 at 06:25

0 Answers0