Closed Thread
Results 1 to 4 of 4

Thread: Capture the screen in a TImage

  1. #1
    MrDiaz is offline Learning Programmer
    Join Date
    Jul 2006
    Posts
    65
    Rep Power
    0

    Capture the screen in a TImage

    With this code I am going to show you how you can capture your screen using dephi. Let's go step by step.

    First we need to insert the component TImage. We are going to use it to paste the screenshot there. Note that you can set up the property stretched to either true or false, with stretch the image will take the whole TImage, this is recommended. You can also try both options and see for yourself the difference.

    This is how my application looks like. You can always customize it with whatever you feel comfortable with.

    Let's go to the coding now, first we create the procedure that will take care of the screenshot.
    Code:
    procedure TakeScreenShot (Image : TBitmap);
    var
    DC : HDC;
    begin
    DC := GetDC (GetDesktopWindow);
    try
    Image.Width:= GetDeviceCaps (DC, HORZRES);
    Image.Height:= GetDeviceCaps (DC, VERTRES);
    BitBlt(Image.Canvas.Handle, 0, 0, Image.Width,
    Image.Height,DC, 0, 0, SRCCOPY);
    finally
    ReleaseDC (GetDesktopWindow, DC);
    end;
    end;
    Take a look that we set up an object named Image, and we especified that it is a bitmap. We will use this to store the image of the screenshot. Then we used
    Code:
    Image.Width:= GetDeviceCaps (DC, HORZRES);
    Image.Height := GetDeviceCaps (DC, VERTRES);
    In that code we use the image width and call the GetDeviceCaps that what it does it take the screen width (horizontal) and the Image.Height takes the vertical size of our skin.

    And now how do we call this procedure to place the screenshot on our image? We call it like this:
    Code:
    TakeScreenShot(Image1.Picture.Bitmap);
    You can use that anywhere you want, in a button OnClick event, on a timer, etc...

    Well that's pretty much it, now go ahead and try the program and make something cool out of it.

    Happy Coding!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    ProgMania is offline Newbie
    Join Date
    Nov 2006
    Posts
    6
    Rep Power
    0
    Nice tutorial. Thanks. I Only got one "bad" thing, Maybe you should consider posting a sample or an example with the tutorial.


  4. #3
    dirkfirst is offline Programming Expert
    Join Date
    May 2006
    Posts
    354
    Rep Power
    23
    The source code would be nice to have.

  5. #4
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    Nice I like it alot!! Thanks mate!!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Java screen capture application in Netbeans.
    By farrell2k in forum Java Tutorials
    Replies: 1
    Last Post: 05-05-2011, 12:13 PM
  2. Beginner How to Capture Screen with Delphi code
    By LuthfiHakim in forum Pascal and Delphi Tutorials
    Replies: 0
    Last Post: 12-03-2010, 03:44 AM
  3. Screen resolution issue and getting rid of gaps around the edges of the screen...
    By HumansAreFriendsNotFood in forum HTML Programming
    Replies: 10
    Last Post: 06-07-2010, 11:07 AM
  4. free screen capture program?
    By zeroradius in forum Technology Ramble
    Replies: 6
    Last Post: 07-19-2008, 08:10 AM
  5. capture screen shot from an application during run time
    By engr in forum Visual Basic Programming
    Replies: 1
    Last Post: 01-29-2007, 01:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts