Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

fast screen capture

Hello, im trying to capture the screen of a OpenGL game, and im trying to make the screen capture as fast as possible, the normal methods are very slow ( 1,300ms~ ) , i would like of a way to capture the screen, even if it will be in bad quality or a small resolution, as long as its fast.
0
SabrWolf
Asked:
SabrWolf
  • 3
  • 2
1 Solution
 
mocartsCommented:
on my PIII 450mhz this code takes 10 ms to capture screen (800x600)

var
iX, iY: integer;
ScreenDC: HDC;
bmp: TBitmap;
begin
 // for performance it's better to get once (somwhere in form create)
 ScreenDC := GetDC(0);
 try
   iX := Screen.Width;
   iY := Screen.Height;
   Bmp := TBitmap.Create;
   try
     bmp.Height := iY;
     bmp.Width := iX;
     if not BitBlt(bmp.Canvas.Handle, 0,0, iX, iY, ScreenDC, 0, 0, SRCCOPY) then
       raise Exception.Create('Error on copy from DC');
     Image1.Picture.Bitmap := bmp;
   finally
     bmp.free;
   end;
 finally
   ReleaseDC(0, ScreenDC);
 end;
end;
wbr, mo.
0
 
SabrWolfAuthor Commented:
hmm is there a way to resize the bmp before i save it to disk ?
0
 
mocartsCommented:
there are two methods to reduce size of bitmap:
- reducing color count:

bmp.PixelFormat := pf8bit; // pf16bit, pf24bit...
Image1.Picture.Bitmap := bmp;

- resizing (with stretchdraw or resampling for better quality (resampling code can be found at search.borland.com)):

with Image1.Picture.Bitmap do begin
  Height := Trunc(bmp.Height / 1.5);
  Width := Trunc(bmp.Width / 1.5);
  Canvas.StretchDraw(Rect(0, 0, Width, Height), bmp);
end;

and combination of both methods.
wbr, mo.
0
 
SabrWolfAuthor Commented:
got any way that doesnt involve TBitmap, i dont want to use the VCL..
0
 
SabrWolfAuthor Commented:
nm. found my answer, thx again!
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now