My basic question is:
-the video card is in 16 or 24 bit mode,
-less than 256 colours are dispayed (some windows colours, some my own),
How can I save (part of) the screen to file in 8 bit mode?
The following approach gives the wrong colours (some kind of standard palette with a number of shades of a number of colours):
ScreenDC := GetDc(0);
MemDc := CreateCompatibleDc(ScreenDC);
MemBitmap := CreateCompatibleBitmap(ScreenDC, SrcRect.width, SrcRect.height);
OldMemBitmap := SelectObject(MemDc, MemBitmap);
BitBlt(MemDC, ..., SrcDC, ...); //SrcDC is the dc of the form
Then I fill a DIB info header with the format I want the bitmap: 1 plane, 8 bits per pixel
and then I call GetDIBits twice: the first time to get the colours into the header, and then to get the bits:
GetDIBits(MemDC, MemBitmap, 0, SrcRect.Height, nil,
GetDIBits(MemDC, MemBitmap, 0, SrcRect.Height, pBits,
After the first GetDIBits, the header does not contain my colours, but some sort of standard colour table, containing a couple of shades of every base colour. Saving the bitmap to file and viewing it with MS Paint indeed shows the wrong colours.
This approach works fine in 8 bit screen mode, but I need to handle screens in higher modes as well.
So my question is: what do I have to do to get the correct colours?