Click to See Complete Forum and Search --> : DIB -> DDB always end up wrong somehow.


monoceres
June 23rd, 2009, 06:13 PM
Hi!

I'm developing a DirectShow player and I wish to have the ability to grab individual frames during playback. This is done with the IVMRWindowlessControl9::GetCurrentImage method. It returns a DIB and it works really good if I just add a BITMAPFILEHEADER and dump it to a file.

However when I try to create a DDB from it (to do further processing) the image always end up wrong somehow, this for example:

ic->pVMRControl->GetCurrentImage(&lpCurrImage))

LPBITMAPINFOHEADER pdib = (LPBITMAPINFOHEADER) lpCurrImage;

HDC dc=GetDC(NULL);

BITMAPINFO bmi;
ZeroMemory(&bmi, sizeof(BITMAPINFO));
CopyMemory(&(bmi.bmiHeader), pdib, sizeof(BITMAPINFOHEADER));


HBITMAP hBitmap = CreateDIBitmap(dc, pdib, CBM_INIT,
pdib+pdib->biSize, &bmi, DIB_PAL_COLORS );


Makes the image uhm, the right half is moved to the left half and vice versa.

So I tried CreateBitmapInstead, like this:

HBITMAP hBitmap = CreateBitmap(pdib->biWidth,(pdib->biHeight),pdib->biPlanes,pdib->biBitCount,
lpCurrImage + ( pdib->biSize + DibPaletteSize(pdib)));


But that made the image turn out upside down.

Please help, going insane over here!

olivthill2
June 24th, 2009, 03:59 AM
CopyMemory(&(bmi.bmiHeader), pdib, sizeof(BITMAPINFOHEADER));You assume the header is the same, but it seems that's not always the case. You should check and sometimes change some of the values of the header.
But that made the image turn out upside down.That's a typical behaviour due to the sign of bmiHeader.biHeight.