?
Solved

Save Screen Shot to File Using Delphi

Posted on 2003-02-22
5
Medium Priority
?
272 Views
Last Modified: 2012-05-04
hi,

i basically want to make a simple program that when you run it pressing the Print Screen button on the keyboard will save the shot to a file instead of just copying in to the clipboard.

it also needs to be able to select the directory you want to save to and automatically increment the value of the file name (eg. screenshot1.bmp, screenshot2.bmp and so on).

Im not sure if this is possible or not so any ideas anyone? i am fairly new to delphi so i need some expert help.

thanks in advance.
0
Comment
Question by:calcanus
[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
5 Comments
 

Accepted Solution

by:
billycl earned 100 total points
ID: 7998757
Insert TImage ant TButton

procedure TForm1.Button1Click(Sender: TObject);
Var H : THANDLE;
    DD : HDC;
    i:integer;
    Path:String;
Begin
 Path:='c:\My Document\';

 if not DirectoryExists(Path) then
ForceDirectories(Path); // Create Directory and SubDirectories  if not exists

i:=1;
while FileExists(Path+'PrintScreen_'+IntToStr(i)+'.bmp') do
 begin
  Inc(i);
 end; // check for first file which not exist

Image1.Width:=Screen.Width; // save whole Image1 to file without white or black border
Image1.Height :=Screen.Height;

 H := GETDESKTOPWINDOW; DD := GETDC(H);
 BitBlt(Image1.Canvas.Handle, 0, 0, Screen.Width, Screen.Height, DD, 0, 0, SRCCOPY);  // from screen to Image1

 Image1.Picture.Graphic. SaveToFile(Path+'PrintScreen_'+IntToStr(i)+'.bmp');

end;
0
 
LVL 1

Assisted Solution

by:User137
User137 earned 100 total points
ID: 8007516
Instead of manually putting TImage on form, it's faster to place "bitmap: TBitmap" at the function's var list.

Bitmap could be created like this:
bitmap:=TBitmap.Create;
bitmap.Width:=Screen.Width;
bitmap.Height:=Screen.Height;

Bitmap can be easily saved with
bitmap.SaveToFile(...

And there were 1 SERIOUS error in code:
you must call
ReleaseDC(GETDESKTOPWINDOW);
0
 

Expert Comment

by:CleanupPing
ID: 9317124
calcanus:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 10

Expert Comment

by:kacor
ID: 9948202
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       to split points between billycl and User137
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Some days and here is the Christmas Time. I wish good luck and good health for you all and for your loved ones

kacor
EE Cleanup Volunteer
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

764 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