从缓冲区创建DIB并将其blit到屏幕

时间:2014-12-11 02:59:30

标签: c++ visual-c++ mfc

我尝试创建自己的图像缓冲区,其中包含红色像素,然后将其与DIB一起用于在屏幕DC上显示。结果是我得到一个充满线条的对话,几乎就像大步走了会发生什么......也许这里有人可以指出我的错误。图像中的线很难看到,但它们交替显示为红色,然后是绿色,然后是蓝色..重复直到对话框的底部。非常感谢有人能帮助我解决这个问题!

//Filling the buffer with all red pixels
uint8_t *buffer = new uint8_t[IMAGEX * IMAGEY * 3];
for (int y = 0; y < IMAGEY; y++)
{
    for (int x = 0; x < IMAGEX * 3; x += 3)
    {
        buffer[y*IMAGEX*3 + x] = 0;
        buffer[y*IMAGEX*3 + x + 1] = 0;
        buffer[y*IMAGEX*3 + x + 2] = 255;
    }
}
pCam->pTestQ->push_back(buffer);


//Displaying the buffer on a DC
BITMAPINFOHEADER bmih = {0};
bmih.biSize = sizeof(BITMAPINFOHEADER);
bmih.biWidth = IMAGEX;
bmih.biHeight = -IMAGEY;
bmih.biPlanes = 1;
bmih.biBitCount = 24;
bmih.biCompression = BI_RGB;
bmih.biXPelsPerMeter = 0;
bmih.biYPelsPerMeter = 0;
bmih.biClrUsed = 0;
bmih.biClrImportant = 0;
bmih.biSizeImage = IMAGEX * IMAGEY * 3;

BITMAPINFO bmi = {0};
bmi.bmiHeader = bmih;
pDC = GetDC();
mDC.CreateCompatibleDC(pDC);

CBitmap img;
img.CreateCompatibleBitmap(pDC, IMAGEX, IMAGEY);
CBitmap* pOldBmp = mDC.SelectObject(&img);

int iRet = SetDIBits(mDC, img, 0, IMAGEY, pCamera->pTestQ->front(), &bmi, DIB_RGB_COLORS);
pDC->BitBlt(0, 0, IMAGEX, IMAGEY, &mDC, 0, 0, SRCCOPY);

mDC.SelectObject(pOldBmp);
ReleaseDC(pDC);

产生的直流blit: http://i.imgur.com/qtImSFE.png

0 个答案:

没有答案