I've tried and tried with no luck. The screen grab just ain't doing anything.
Anybody any ideas?
// First of all grab the image from the screen
IDirect3DSurface9 *SrcSurface = 0;
D3DLOCKED_RECT SrcRect;
D3DSURFACE_DESC SrcDesc;
int wid = dbScreenWidth();
int hgt = dbScreenHeight();
int dep = 32; //dbGetBackbufferDepth();
IDirect3DDevice9 *screen = dbGetDirect3DDevice();
screen->CreateOffscreenPlainSurface(wid, hgt, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &SrcSurface, NULL);
screen->GetFrontBufferData(0, SrcSurface);
SrcSurface->GetDesc(&SrcDesc);
SrcSurface->LockRect(&SrcRect, 0, 0);
int pit = SrcRect.Pitch;
unsigned char *SrcAddr = (unsigned char*)SrcRect.pBits;
HDC hScrDC, hMemDC;
HBITMAP hBitmap;
//SrcSurface->GetDC( &hScrDC );
hScrDC = GetDC( g_pGlob->hWnd );
hMemDC = CreateCompatibleDC( hScrDC );
// CreateCompatibleBitmap() just doesn't work at all!
//hBitmap = CreateCompatibleBitmap(hScrDC, SrcDesc.Width, SrcDesc.Height);
//SelectObject(hMemDC, hBitmap);
// TRYING DIB
BITMAPINFO bmh;
ZeroMemory(&bmh, sizeof(BITMAPINFO));
bmh.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmh.bmiHeader.biWidth = wid;
bmh.bmiHeader.biHeight = hgt;
bmh.bmiHeader.biPlanes = 1;
bmh.bmiHeader.biBitCount = 32;
bmh.bmiHeader.biCompression = BI_RGB;
bmh.bmiHeader.biSizeImage = 0;
bmh.bmiHeader.biXPelsPerMeter = 0;
bmh.bmiHeader.biYPelsPerMeter = 0;
bmh.bmiHeader.biClrUsed = 0;
bmh.bmiHeader.biClrImportant = 0;
void *pbits;
//char *pbits = new char[wid*hgt*4];
hBitmap = CreateDIBSection(hMemDC, &bmh, DIB_RGB_COLORS, &pbits, 0, 0);
//hBitmap = CreateDIBitmap(hMemDC,&bmh.bmiHeader,CBM_INIT,pbits,&bmh,DIB_RGB_COLORS);
SelectObject( hScrDC, 0);
BitBlt(hMemDC, 0, 0, SrcDesc.Width, SrcDesc.Height, hScrDC, 0, 0, SRCCOPY);
// GRAB CODE
DeleteObject( hBitmap );
SrcSurface->ReleaseDC(hScrDC);
DeleteDC( hMemDC );
// release the surface (give it freedom again)
SrcSurface->UnlockRect();
SrcSurface->Release();
SrcSurface=0;
// delete the buffer now we're done with it
//delete pbits;
It creates just blank images...
EDIT: Just updated using BITMAPINFO instead of BITMAPINFOHEADER but still not working...
EDIT2: I have even just added this instead of BitBlt in case BitBlt wasn't working... (Everything runs but still saves blank images.)
//BitBlt(hMemDC, 0, 0, wid, hgt, hScrDC, 0, 0, SRCCOPY);
__asm {
mov edx, [pbits] // destination
mov ecx, [SrcAddr] // source
mov eax, [hgt] // height of bitmap
_lhgt: push eax // save hgt counter
push ecx // save source address
mov ebx, [wid] // pixel count across
_lwid: mov eax, [ecx] // grab pixel
mov [edx], eax // store in new bitmap
add ecx, 4 // next pixel across
add edx, 4
dec ebx
jne _lwid // continue until end
pop ecx // restore source address
add ecx, [pit] // add pitch
pop eax
dec eax
jne _lhgt // next line
}
Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!