Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Save Screen Shot to File Using Delphi

Posted on 2003-02-22
5
Medium Priority
?
274 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
4 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline

581 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