---
---
---
---
---
---
---
---
---
void PrintCallback::AnalyzeFrame(CTestColorPoolDlg* pDlg, const VideoFrameRef& frame)
{
int h = frame.getHeight();
int w = frame.getWidth();
RGB888Pixel* pColor = NULL;
CClientDC dc(pDlg);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap bmp;
bmp.CreateCompatibleBitmap(&dc, h, w);
memDC.SelectObject(&bmp);
BITMAPINFO bmpInfo;
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth = h;
bmpInfo.bmiHeader.biHeight = -w;
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biBitCount = 24;
bmpInfo.bmiHeader.biCompression = BI_RGB;
bmpInfo.bmiHeader.biSizeImage = 0;
bmpInfo.bmiHeader.biXPelsPerMeter = 50;
bmpInfo.bmiHeader.biYPelsPerMeter = 50;
bmpInfo.bmiHeader.biClrUsed = 0;
bmpInfo.bmiHeader.biClrImportant = 0;
long nLnBytes = (bmpInfo.bmiHeader.biWidth * 3 + 3) / 4 * 4;
BYTE* pData = new BYTE[nLnBytes * abs(bmpInfo.bmiHeader.biHeight)];
memset(pData, 0, nLnBytes * abs(bmpInfo.bmiHeader.biHeight));
switch (frame.getVideoMode().getPixelFormat())
{
case PIXEL_FORMAT_RGB888:
pColor = (RGB888Pixel*)frame.getData(); // get array' address of image that in pixels
// traverses the pixels according to the height and width of the image
for (int i = 0; i < h; i++)
{
for (int j = 0; j < w; j++)
{
COLORREF& d = (COLORREF&)pColor[i * w + j]; // mandatory reference 3bytes? 4bytes?
pData[i * nLnBytes + j * 3 + 1] = GetGValue(d); //g
pData[i * nLnBytes + j * 3 + 2] = GetRValue(d); //r
pData[i * nLnBytes + j * 3 + 3] = GetBValue(d); //b
}
}
SetDIBits(dc.m_hDC, bmp, 0, abs(bmpInfo.bmiHeader.biHeight), pData, &bmpInfo, DIB_RGB_COLORS);
delete[]pData;
dc.BitBlt(0, 0, bmpInfo.bmiHeader.biWidth, abs(bmpInfo.bmiHeader.biHeight), &memDC, 0, 0, SRCCOPY);
break;
default:
::MessageBox(pDlg->GetSafeHwnd(), L"Unknown format\n", _T("错误提示"), MB_OK);
break;
}
}
我直接问号