Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Taking a shot of the screen?

Posted on 2000-05-13
13
Medium Priority
?
236 Views
Last Modified: 2010-04-04
How can I take a shot of the screen (by not using a tbitmap component)? I need to do this in a console application where exe size is critical so i am not using and graphic libraries or forms.pas

--Olympus
0
Comment
Question by:Olympus
13 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 2807633
hi,
as you are a new user you should probably read here:

http://www.experts-exchange.com/info/howto.htm#20
0
 

Author Comment

by:Olympus
ID: 2807680
i know, unfortunately i have no points to offer as of yet.
0
 

Author Comment

by:Olympus
ID: 2807688
Adjusted points from 0 to 50
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Olympus
ID: 2807689
k i just got more, here...
0
 
LVL 15

Expert Comment

by:simonet
ID: 2807754
Here's a much better approach than the one suggested:

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(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,
         x,
         y,
         SRCCOPY);
 {release the screen dc}
  ReleaseDc(0, dc);
end;



This one handles palette entries in a much better fashion than simply capturing HDC(0).

Alex
0
 
LVL 3

Expert Comment

by:bryan7
ID: 2807785
listenning
0
 

Author Comment

by:Olympus
ID: 2807797
"(by not using a tbitmap component)"
0
 
LVL 15

Expert Comment

by:simonet
ID: 2807898
Where do you want to store the resulting image then? It must be stored somewhere.

Alex
0
 

Author Comment

by:Olympus
ID: 2808561
it can be stored anywhere as long as it doesnt use Forms.Pas or Graphics.pas, my console app cant increase much more in size (its already 119kb)
0
 
LVL 15

Accepted Solution

by:
simonet earned 200 total points
ID: 2808804
Use the code I sent you with a Windows TBitmap class:

var
   bmp : Windows.TBitmap;


It doesn't add all the overhead of a Delphi Bitmap class, so your application will remain just as light.

Alex
0
 

Author Comment

by:Olympus
ID: 2808879
as  a followup question, how would i do jpeg compression or some sort of bmp compression without using the delphi classes again?
0
 

Author Comment

by:Olympus
ID: 2808996
and how would i use BitBlt with the windows bitmap?
the first value of it is a handle, what can i put there?

BitBlt(<whatgoeshere?>, 0, 0, bm.bmWidth, bm.bmHeight, hDC, 0, 0, SRCCOPY);
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question