View Full Version : screenshots
arthurprs
07-02-2009, 08:24 PM
im developing an app that take screenshots of games,
at the moment i use this method, but it don't work in some windows vista/seven systems
function GetPrintScreen(wnd: HWND): TBitmap;
var
h, w: Integer;
dc: HDC;
rect: TRect;
begin
dc := GetDC(wnd);
if (dc = 0) or (not GetClientRect(wnd, rect)) then
begin
Result := nil;
Exit;
end;
w := rect.Right - rect.Left;
h := rect.Bottom - rect.Top;
Result := TBitmap.Create;
Result.Width := w;
Result.Height := h;
BitBlt(
Result.Canvas.Handle, 0, 0,
w, h,
dc, 0, 0,
SRCCOPY);
ReleaseDC(wnd, dc);
end;
so,
someone know another way to get screenshots?
jdarling
07-02-2009, 10:13 PM
Google code search returns the following:
procedure MakeDesktopScreenshot( const FN : string );
var
DesktopDC : HDC;
myBitmap : TBitmap;
ScreenHandle : HWND;
begin
myBitmap := TBitmap.Create;
try
ScreenHandle := GetDesktopWindow;
DesktopDC := GetDC( ScreenHandle );
try
myBitmap.Width := screen.Width;
myBitmap.Height := screen.Height;
BitBlt( myBitmap.Canvas.Handle, 0, 0, screen.Width, screen.Height, DesktopDC, 0, 0, SRCCOPY );
if ( FN <> '' ) then
myBitmap.SaveToFile( FN )
else
Clipboard.Assign( myBitmap );
finally
ReleaseDC( ScreenHandle, DesktopDC );
end;
finally
myBitmap.Free;
end;
end; // MakeDesktopScreenshot
procedure MakeFormScreenshot(hWindow: HWND; const Filename : string );
var
Left, Top, Width, Height: Word;
R: TRect;
dc: HDC;
lpPal: PLOGPALETTE;
BM : TBitmap;
begin
{Check if valid window handle}
if not IsWindow(hWindow) then Exit;
{Retrieves the rectangular coordinates of the specified window}
GetWindowRect(hWindow, R);
Left := R.Left;
Top := R.Top;
Width := R.Right - R.Left;
Height := R.Bottom - R.Top;
{get the screen dc}
dc := GetDc(0);
if (dc = 0) then
exit;
BM := TBitmap.Create;
try
bm.Width := Width;
bm.Height := Height;
{do we have a palette device?}
if (GetDeviceCaps(dc, RASTERCAPS) and
RC_PALETTE = RC_PALETTE) then
begin
{allocate memory for a logical palette}
GetMem(lpPal,
SizeOf(TLOGPALETTE) +
(255 * SizeOf(TPALETTEENTRY)));
{zero it out to be neat}
FillChar(lpPal^,
SizeOf(TLOGPALETTE) +
(255 * SizeOf(TPALETTEENTRY)),
#0);
{fill in the palette version}
lpPal^.palVersion := $300;
{grab the system palette entries}
lpPal^.palNumEntries :=
GetSystemPaletteEntries(dc,
0,
256,
lpPal^.palPalEntry);
if (lpPal^.PalNumEntries <> 0) then
begin
{create the palette}
bm.Palette := CreatePalette(lpPal^);
end;
FreeMem(lpPal, SizeOf(TLOGPALETTE) +
(255 * SizeOf(TPALETTEENTRY)));
end;
{copy from the screen to the bitmap}
BitBlt(bm.Canvas.Handle,
0,
0,
Width,
Height,
Dc,
Left,
Top,
SRCCOPY);
{release the screen dc}
ReleaseDc(0, dc);
BM.SaveToFile( Filename );
finally
BM.Free;
end;
end;
Haven't tried it, as usually I just include it in my games via a quick key.
arthurprs
08-02-2009, 06:40 PM
jdarling, this is the same method that i use, via GDI, im searching for another way :|
arthurprs
12-02-2009, 11:05 PM
after some insente googling i found that creating a opengl fullscreen context and then use glReadPixels() can work
but how can i do that?
thanks.
chronozphere
13-02-2009, 07:17 PM
Google is your friend. ;)
http://www.gamedev.net/community/forums/topic.asp?topic_id=436385
arthurprs
14-02-2009, 04:08 AM
Google is your friend. ;)
http://www.gamedev.net/community/forums/topic.asp?topic_id=436385
hi chronozphere, i found how to capture the screenshots,
but i don't know how to create a opengl fullscreen context over the current running game window
KidPaddle
14-02-2009, 08:15 AM
Only German, but with samples for saving screenshots to bmp or tga file format.
http://wiki.delphigl.com/index.php/Screenshot
I try to translate the comments for bimtap version
procedure ScreenShot(const Name : string);
var
F : file;
FileInfo: BITMAPINFOHEADER;
FileHeader : BITMAPFILEHEADER;
pPicData:Pointer;
Viewport : array[0..3] of integer;
begin
// clear header
ZeroMemory(@FileHeader, SizeOf(BITMAPFILEHEADER));
ZeroMemory(@FileInfo, SizeOf(BITMAPINFOHEADER));
// query screen size of viewpoint
glGetIntegerv(GL_VIEWPORT, @Viewport);
// Init header
FileHeader.bfType := 19778; //$4D42 = 'BM'
FileHeader.bfOffBits := SizeOf(BITMAPINFOHEADER)+SizeOf(BITMAPFILEHEADER);
// setup bitmap header
FileInfo.biSize := SizeOf(BITMAPINFOHEADER);
FileInfo.biWidth := Viewport[2];
FileInfo.biHeight := Viewport[3];
FileInfo.biPlanes := 1;
FileInfo.biBitCount := 32;
FileInfo.biSizeImage := FileInfo.biWidth*FileInfo.biHeight*(FileInfo.biBit Count div 8);
// setup file size
FileHeader.bfSize := FileHeader.bfOffBits + FileInfo.biSizeImage;
// get memory for image
GetMem(pPicData, FileInfo.biSizeImage);
try
// read pixels from opengl frame buffer
glReadPixels(0, 0, Viewport[2], Viewport[3], GL_BGRA, GL_UNSIGNED_BYTE, pPicData);
// write image to disk, modern version are using streams
AssignFile(f, name);
Rewrite( f,1 );
try
BlockWrite(F, FileHeader, SizeOf(BITMAPFILEHEADER));
BlockWrite(F, FileInfo, SizeOf(BITMAPINFOHEADER));
BlockWrite(F, pPicData^, FileInfo.biSizeImage );
finally
CloseFile(f);
end;
finally
// free reserved pixel data
FreeMem(pPicData, FileInfo.biSizeImage);
end;
end;
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.