HWND hDesktopWnd = GetDesktopWindow();
HDC hdc = GetDC(hDesktopWnd);
SShot s;
s.x = 0;
s.y = 0;
s.w = GetSystemMetrics(SM_CXSCREEN);
s.h = GetSystemMetrics(SM_CYSCREEN);
s.hdc = CreateCompatibleDC(hdc);
s.hbmp = CreateCompatibleBitmap(hdc,s.w,s.h);
s.ex_hbmp = (HBITMAP)SelectObject(s.hdc, s.hbmp);
BitBlt(s.hdc,0,0,s.w,s.h,hdc,s.x,s.y,SRCCOPY);
//StretchBlt(s.hdc,0,0,s.w,s.h,hdc,0,s.h,s.w,-s.h,SRCCOPY);
ReleaseDC(hDesktopWnd,hdc);
/////////////////////////////////////////////////////////////////////////////////////////
// Allocate buffers
DWORD NumPixels = s.w * s.h;
Buffers.ScreenShot.Allocate(NumPixels * 4);
Buffers.Converted.Allocate(NumPixels * 3);
// Fill the ScreenShot buffer
GetBitmapBits(s.hbmp, Buffers.ScreenShot.GetBufferSize(), Buffers.ScreenShot.GetBuffer());
// Convert it to 24 bits in another buffer
DWORD Ret = ConvertTo24bits(Buffers.Converted.GetBuffer(), Buffers.ScreenShot.GetBuffer(), Buffers.ScreenShot.GetBufferSize());
/////////////////////////////////////////////////////////////////////////////////////////
// Release the bitmap handles
if(SelectObject(s.hdc, s.hbmp)){
DeleteObject(s.hbmp);
DeleteDC(s.hdc);
}
The problem is, if the screen resolution use another color format than 32 bits, this code won't work.
So, i would like to know how can i convert the image to 24 bits from any pixel format the desktop is currently using.
Thx.