一.IMvdImage转CBitmap
1.初始化IMvdImage对象
IMvdImage* m_pOtherImage = nullptr;
int nRet = CreateImageInstance(&m_pOtherImage);
if (MVD_OK != nRet)
{
ShowErrorMsg(L"CreateImageInstance", 1);
return;
}
m_pOtherImage->InitImage("E:\\vs work\\hk\\resource\\earth-3840x2160-clouds-4k-23359.jpg");
2.获取m_pOtherImage内的图像数据
int iWidth = m_pOtherImage->GetWidth();
int iHeight = m_pOtherImage->GetHeight();
MVD_PIXEL_FORMAT pixelFormat = m_pOtherImage->GetPixelFormat();
MVD_IMAGE_DATA_INFO* temp = m_pOtherImage->GetImageData();
unsigned char* data = (unsigned char*)malloc(iWidth * iHeight * 4 * sizeof(char));
switch (pixelFormat)
{
case MVD_PIXEL_MONO_08: {
if (data != nullptr) {
for (int i = 0; i < iWidth * iHeight; i++) {
data[i * 4] = temp->stDataChannel[0].pData[i];
data[i * 4 + 1] = temp->stDataChannel[0].pData[i];
data[i * 4 + 2] = temp->stDataChannel[0].pData[i];
data[i * 4 + 3] = temp->stDataChannel[0].pData[i];
}
}
break;
}
case MVD_PIXEL_RGB_RGB24_C3: {
if (data != nullptr) {
for (int i = 0; i < iWidth * iHeight; i++) {
data[i * 4] = temp->stDataChannel[0].pData[i * 3 + 2];
data[i * 4 + 1] = temp->stDataChannel[0].pData[i * 3 + 1];
data[i * 4 + 2] = temp->stDataChannel[0].pData[i * 3];
data[i * 4 + 3] = 255;
}
}
break;
}
default:
break;
}
CBitmap* m_loadBitmap = new CBitmap();
m_loadBitmap->CreateBitmap(iWidth, iHeight, 1, 32, data);
CImage img;
img.Attach(*m_loadBitmap);
img.Save(_T("aaa.bmp"));
3.结论
经过测试,转换后的CBitmap对象可被设备上下文(DC)选入以实现绘图,如图所示
8位,1280*1024灰度图(MVD_PIXEL_MONO_08)

24位,3840*2160彩色图(MVD_PIXEL_RGB_RGB24_C3)
