Solved

Taking a shot of the screen?

Posted on 2000-05-13
13
227 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
 

Author Comment

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

Expert Comment

by:alexdg
ID: 2807733
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 107
Syntax Check Delphi Seattle IOS app without MAC ? 1 92
oracle global variables 4 63
control image tags in a string ? 12 111
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now