我正在尝试Bitmap^
从unsigned char* databuffer
. 我需要非常有效地做到这一点 - 这个函数每秒调用多次,并且在运行后更新 GUI。我的代码是:
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);
当最后一行运行时,抛出异常:“句柄无效。(来自 HRESULT 的异常:0x80070006(E_HANDLE))”
还有另一种方法吗?(我尝试先将 unsigned char* 转换为 Bitmap^,然后再转换为BitmapSource^
,但这需要太多时间)。
谢谢。