Solved

Taking a shot of the screen?

Posted on 2000-05-13
13
229 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 68
delphi parse string to params 3 121
Tembedded WB animatid gifs not animated on some pcs 2 79
how to update exe applicatio from internet ? 6 76
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

785 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