A
Hallo,
folgendes Problem, ich erstelle Screenshots uns Speichere diese als BMP ab. Bei 32bit ist alles OK, bei 16bit ist ein blaustich drin, und bei 8bit ist es nur noch weiß. Wer kann mir da mal fix weiterhelfen?
bool CPSDlg::Screenshot(CWnd* pWnd)
{
CWindowDC CWndDC(pWnd);
CDC CMemDC;
CBitmap CShotBmp;
CPalette* test;
test = CWndDC.GetCurrentPalette();
CMemDC.CreateCompatibleDC(&CWndDC);
CRect CClientRect;
CClientRect.left = CClientRect.top = 0;
CClientRect.right = ::GetSystemMetrics(SM_CXSCREEN);
CClientRect.bottom = ::GetSystemMetrics(SM_CYSCREEN);
CShotBmp.CreateCompatibleBitmap(&CWndDC, CClientRect.Width(),CClientRect.Height());
CMemDC.SelectObject(&CShotBmp);
CMemDC.BitBlt(0,0,CClientRect.Width(),CClientRect.Height(),&CWndDC,0,0,SRCCOPY);
BITMAP bitmap;
CShotBmp.GetBitmap(&bitmap);
int size = bitmap.bmWidth*bitmap.bmHeight*bitmap.bmBitsPixel/8;
BYTE *lpBits = new BYTE[size];
::GetBitmapBits((HBITMAP)CShotBmp,size,lpBits);
WriteBmp(&bitmap,(int*)lpBits);
return true;
}
void CPSDlg::WriteBmp(BITMAP *bmp, int* data)
{
BITMAPINFO Bmi;
memset(&Bmi,0,sizeof(BITMAPINFO));
Bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
Bmi.bmiHeader.biWidth = bmp->bmWidth;
Bmi.bmiHeader.biHeight = bmp->bmHeight;
Bmi.bmiHeader.biPlanes = 1;
Bmi.bmiHeader.biBitCount =bmp->bmBitsPixel;
Bmi.bmiHeader.biCompression = BI_RGB;
Bmi.bmiHeader.biSizeImage = bmp->bmHeight*bmp->bmWidth*bmp->bmBitsPixel/8;
FILE* image = fopen ("C:\\Test.bmp","wb");
if(image==0)
return;
int h = abs(Bmi.bmiHeader.biHeight);
int w = abs(Bmi.bmiHeader.biWidth);
Bmi.bmiHeader.biHeight=-h;
Bmi.bmiHeader.biWidth=w;
int sz = Bmi.bmiHeader.biSizeImage;
BITMAPFILEHEADER bfh;
bfh.bfType=('M'<<8)+'B';
bfh.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
bfh.bfSize=sz+bfh.bfOffBits;
bfh.bfReserved1=0;
bfh.bfReserved2=0;
fwrite(&bfh,sizeof(bfh),1,image);
fwrite(&Bmi.bmiHeader,sizeof(BITMAPINFOHEADER),1,image);
fwrite(data,sz,1,image);
fclose(image);
}
Im Voraus vielen Dank.
Gruss Sven