Board index » delphi » Screen capture, snapshot, print screen

Screen capture, snapshot, print screen

I want to know how to capture the screen in Delphi then save to a bitmap.
Anyone has an example for this?

Please help, thanks!

--
         __  __ ______ ____   _____
   ---= / /_/ //_  __// __ \ / ___/ =---   Maxime Asselin
 ---== / __  /  / /  / _  _// /___  ==---  R&D Programmer-Analyst
  --= /_/ /_/  /_/  /_/ \_\ \____/  =--    HTRC Automation

 

Re:Screen capture, snapshot, print screen


Maxime Asselin heeft geschreven in bericht ...

Quote
>I want to know how to capture the screen in Delphi then save to a bitmap.
>Anyone has an example for this?

There is a  Capture component at
http://www.high-logic.com/

Besides the whole screen, it also captures windows and objects.

Hope this helps,

Erwin

Re:Screen capture, snapshot, print screen


I'm not going to spend 100$ on a component while all I need is to do is
something like:

BOOL BitBlt(
    HDC  hdcDest, // handle of destination device context
    int  nXDest, // x-coordinate of destination rectangle's upper-left
corner
    int  nYDest, // x-coordinate of destination rectangle's upper-left
corner
    int  nWidth, // width of destination rectangle
    int  nHeight, // height of destination rectangle
    HDC  hdcSrc, // handle of source device context
    int  nXSrc, // x-coordinate of source rectangle's upper-left corner
    int  nYSrc, // y-coordinate of source rectangle's upper-left corner
    DWORD  dwRop  // raster operation code
);

And use NULL for hdcSrc...  I just wanted an example, it just doesn't work
in Delphi.
Is it still possible to get help in the forums or is it just a place where
people sell their components?

Quote
Erwin Denissen wrote in message <916069889.958...@tbird.introweb.nl>...
>Maxime Asselin heeft geschreven in bericht ...
>>I want to know how to capture the screen in Delphi then save to a bitmap.
>>Anyone has an example for this?

>There is a  Capture component at
>http://www.high-logic.com/

>Besides the whole screen, it also captures windows and objects.

>Hope this helps,

>Erwin

Re:Screen capture, snapshot, print screen


No it doesn't, the component is 100$!!!

I'm not going to spend 100$ on a component while all I need is to do is
something like:

BOOL BitBlt(
    HDC  hdcDest, // handle of destination device context
    int  nXDest, // x-coordinate of destination rectangle's upper-left
corner
    int  nYDest, // x-coordinate of destination rectangle's upper-left
corner
    int  nWidth, // width of destination rectangle
    int  nHeight, // height of destination rectangle
    HDC  hdcSrc, // handle of source device context
    int  nXSrc, // x-coordinate of source rectangle's upper-left corner
    int  nYSrc, // y-coordinate of source rectangle's upper-left corner
    DWORD  dwRop  // raster operation code
);

And use NULL for hdcSrc...  I just wanted an example, it just doesn't work
in Delphi.
Is it still possible to get help in the forums or is it just a place where
people sell their components?

Quote
Erwin Denissen wrote in message <916069889.958...@tbird.introweb.nl>...
>Maxime Asselin heeft geschreven in bericht ...
>>I want to know how to capture the screen in Delphi then save to a bitmap.
>>Anyone has an example for this?

>There is a  Capture component at
>http://www.high-logic.com/

>Besides the whole screen, it also captures windows and objects.

>Hope this helps,

>Erwin

Re:Screen capture, snapshot, print screen


Maxime Asselin heeft geschreven in bericht ...

Quote
>I'm not going to spend 100$ on a component while all I need is to do is
>something like:

As a matter of fact it's $20. Source, Documantation and Examples included.

Good luck,

Erwin Denissen

Re:Screen capture, snapshot, print screen


In article <mLom2.137$FJ5....@wagner.videotron.net>, "Maxime Asselin"

Quote
<Maxime.Asse...@bigfoot.com> writes:
>I want to know how to capture the screen in Delphi then save to a bitmap.
>Anyone has an example for this?

This was posted a little while ago :-

Save to a file :-

var
  MemDC : hDC;
  MyBitMap : TBitMap;
begin
  MyBitMap := TBitMap.Create;
  with MyBitMap do begin
    Width := Screen.Width;
    Height := Screen.Height;
  end;
  MemDC:=GetDC(0);
  BitBlt(MyBitmap.Canvas.Handle, 0, 0, Screen.Width, Screen.Height,
         MemDC, 0, 0, SRCCOPY);
  MyBitmap.SaveToFile('C:\TEMP\DESKTOP.BMP');
  ReleaseDC(0,MemDC);
  MyBitMap.Free;
end;.

Restore from file :-

var
  MemDC : hDC;
  MyBitMap : TBitMap;
begin
  MyBitMap := TBitMap.Create;
  MyBitmap.LoadFromFile('C:\TEMP\DESKTOP.BMP');
  MemDC:=GetDC(0);
  BitBlt(MemDC, 0, 0, Screen.Width, Screen.Height,
        MyBitmap.Canvas.Handle, 0, 0, SRCCOPY);
  ReleaseDC(0,MemDC);
  MyBitMap.Free;
end;.

Alan Lloyd
alangll...@aol.com

Re:Screen capture, snapshot, print screen


Quote
Maxime Asselin wrote:

> I want to know how to capture the screen in Delphi then save to a bitmap.
> Anyone has an example for this?

> Please help, thanks!

Here something that works (even with Palettes)

procedure ScreenShot(x : integer;
                     y : integer;
                     Width : integer;
                     Height : integer;
                     bm : TBitMap);
var
  dc: HDC;
  lpPal : PLOGPALETTE;
begin
 {test width and height}
  if ((Width = 0) OR
      (Height = 0)) then begin
    exit;
  end;
  bm.Width := Width;
  bm.Height := Height;
 {get the screen dc}
  dc := GetDc(0);
  if (dc = 0) then begin
    exit;
  end;
 {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(TPALET{*word*249}TRY)));
   {zero it out to be neat}
    FillChar(lpPal^,
             sizeof(TLOGPALETTE) +
             (255 * sizeof(TPALET{*word*249}TRY)),
             #0);
   {fill in the palette version}
    lpPal^.palVersion := $300;
   {grab the system palette entries}
    lpPal^.palNumEntries :=
      GetSystemPalet{*word*249}tries(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(TPALET{*word*249}TRY)));
  end;
 {copy from the screen to the bitmap}
  BitBlt(bm.Canvas.Handle,
         0,
         0,
         Width,
         Height,
         Dc,
         x,
         y,
         SRCCOPY);
 {release the screen dc}
  ReleaseDc(0, dc);
end;

Joe
--
Joe C. Hecht
http://home1.gte.net/joehecht/index.htm

Other Threads