Surface to BMP
Does anyone have a chunk of code that would accomplish the purpose of the following function?
void SurfaceToBitmap(LPDIRECTDRAWSURFACE, char *filename);
I want to record a movie of my game action, but when I use the windows screen capture, it messes up badly. All I want to do is call that function above to dump a bitmap of the chosen surface to disk, every time I page flip.
Anyone done this yet? I''m using 16 color, but I was hoping there was a way to do it with the windows API, so I wouldn''t have to muck about with pixel formats and bitmap headers.
-- Goodlife
-----------------------------
Think of your mind as a door on a house. Leave the door always closed, and it's not a house, it's a prison. Leave the door always open, and it's not a house, it's a wilderness-- all the vermin creep in.
I have a bitmap saving routine that doesn''t use windows functions. I do all of the conversions for the 16 bit color and I use the bitmap headers (so I don''t know if you want it). If you want it I can send it to you (I''m at work now so I don''t have it on me).
Hey, IShadow, that would be terrific, thanks!
My email is jraptis@csmi.com!
-- Goodlife
-----------------------------
Think of your mind as a door on a house. Leave the door always closed, and it's not a house, it's a prison. Leave the door always open, and it's not a house, it's a wilderness-- all the vermin creep in.
My email is jraptis@csmi.com!
-- Goodlife
-----------------------------
Think of your mind as a door on a house. Leave the door always closed, and it's not a house, it's a prison. Leave the door always open, and it's not a house, it's a wilderness-- all the vermin creep in.
BOOL DC_ScreenShot(HDC hDC, int width, int height, int bits, char *Name){ BITMAPFILEHEADER bfh; BITMAPINFOHEADER bih; HDC memDC = NULL; HBITMAP bitmap = NULL; HBITMAP oldbit = NULL; FILE *file = NULL; void *data= NULL; int bpp, datasize; BOOL success = FALSE; if (!hDC) return 0; if (bits <= 0) return 0; if (width <= 0) return 0; if (height <= 0) return 0; bpp = bits / 8; if (bpp < 2) bpp = 2; if (bpp > 3) bpp = 3; datasize = width * bpp * height; if (width * bpp % 4) { datasize += height * (4 - width * bpp % 4); } memset((void*)&bfh, 0, sizeof(bfh)); bfh.bfType = ''B''+(''M''<<8); bfh.bfSize = sizeof(bfh)+sizeof(bih)+datasize; bfh.bfOffBits = sizeof(bfh)+sizeof(bih); memset((void*)&bih, 0, sizeof(bih)); bih.biSize = sizeof(bih); bih.biWidth = width; bih.biHeight = height; bih.biPlanes = 1; bih.biBitCount = bpp * 8; bih.biCompression = BI_RGB; bitmap = CreateDIBSection(NULL, (BITMAPINFO *)&bih, DIB_RGB_COLORS, &data, NULL, 0); if (!bitmap) goto cleanup; if (!data) goto cleanup; memDC = CreateCompatibleDC(hDC); if (!memDC) goto cleanup; oldbit = SelectObject(memDC, bitmap); if (oldbit <= 0) goto cleanup; success = BitBlt(memDC, 0, 0, width, height, hDC, 0, 0, SRCCOPY); if (!success) goto cleanup; file = fopen(Name, "wb"); if (!file) { MakeDir(Name); file = fopen(Name, "wb"); } if (!file) goto cleanup; fwrite((void*)&bfh, sizeof(bfh), 1, file); fwrite((void*)&bih, sizeof(bih), 1, file); fwrite((void*)data, 1, datasize, file); success = TRUE; cleanup: if (oldbit > 0) SelectObject(memDC, oldbit); if (memDC) DeleteDC(memDC); if (file) fclose(file); if (bitmap) DeleteObject(bitmap); return success;}HRESULT ScreenShot(LPDIRECTDRAWSURFACE surf, char *Name){ DDSURFACEDESC ddsd; HRESULT res = DD_OK; HDC surfDC = NULL; BOOL success = FALSE; if (!surf) return DDERR_INVALIDOBJECT; ZeroMemory(&ddsd,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); res=surf->GetSurfaceDesc(&ddsd); if (FAILED(res)) return res; res=surf->GetDC(&surfDC); if (FAILED(res) return res; success = DC_ScreenShot(surfDC, ddsd.dwWidth, ddsd.dwHeight, ddsd.ddpfPixelFormat.dwRGBBitCount, Name); if (surfDC) surf->ReleaseDC(surfDC); return res;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement