我看到这个问题的答案对于如何将 cv::Mat 图像打印到 MFC 应用程序中非常受欢迎。
但是,我想知道那里是否存在内存泄漏?或者如果没有,那怎么可能?
具体来说,我想知道这memset(bmih, 0, sizeof(*bmih))
部分。是 MFC 以某种方式管理这里的内存吗?有人可以提供一些有关此的信息吗?
void COpenCVTestView::FillBitmapInfo(BITMAPINFO* bmi, int width, int height, int bpp, int origin)
{
assert(bmi && width >= 0 && height >= 0 && (bpp == 8 || bpp == 24 || bpp == 32));
BITMAPINFOHEADER* bmih = &(bmi->bmiHeader);
// this part shouldn't leak?
memset(bmih, 0, sizeof(*bmih));
bmih->biSize = sizeof(BITMAPINFOHEADER);
bmih->biWidth = width;
bmih->biHeight = origin ? abs(height) : -abs(height);
bmih->biPlanes = 1;
bmih->biBitCount = (unsigned short)bpp;
bmih->biCompression = BI_RGB;
if (bpp == 8)
{
RGBQUAD* palette = bmi->bmiColors;
for (int i = 0; i < 256; i++)
{
palette[i].rgbBlue = palette[i].rgbGreen = palette[i].rgbRed = (BYTE)i;
palette[i].rgbReserved = 0;
}
}
}