Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Capture the screen in a TImage


  • Please log in to reply
3 replies to this topic

#1 MrDiaz


    CC Resident

  • Just Joined
  • PipPipPipPip
  • 64 posts

Posted 03 July 2006 - 03:29 PM

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.
procedure TakeScreenShot (Image : TBitmap);
DC := GetDC (GetDesktopWindow);
Image.Width:= GetDeviceCaps (DC, HORZRES);
Image.Height:= GetDeviceCaps (DC, VERTRES);
BitBlt(Image.Canvas.Handle, 0, 0, Image.Width,
Image.Height,DC, 0, 0, SRCCOPY);
ReleaseDC (GetDesktopWindow, DC);
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
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:
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!
  • 0

#2 ProgMania


    CC Lurker

  • Just Joined
  • Pip
  • 6 posts

Posted 02 December 2006 - 08:16 AM

Nice tutorial. Thanks. I Only got one "bad" thing, Maybe you should consider posting a sample or an example with the tutorial.

  • 0

#3 dirkfirst


    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 351 posts

Posted 03 December 2006 - 11:21 AM

The source code would be nice to have.
  • 0

#4 TcM


    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 06 December 2006 - 09:57 AM

Nice :) I like it alot!! Thanks mate!!
  • 0

Also tagged with one or more of these keywords: timer

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download