Solved

Taking a shot of the screen?

Posted on 2000-05-13
13
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 50 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

628 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