Screenshot: capture the current program interface and save it to the BMP image.

Source: Internet
Author: User
Tags bmp image

Directly run the Code:

 

 unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Clipbrd;

type
TForm1 = class(TForm)
btn1: TButton;
dlgSave1: TSaveDialog;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
var
bmp:TBitmap;
MyRect:TRect;
Myrect2:TRect;
canvas:TCanvas;
DC:HDC;
b:TPoint;
aa:TPoint;
begin
ShowMessage('---------------');
bmp := TBitmap.Create;
bmp.Width := Form1.Width;
bmp.Height := form1.Height;
MyRect := Rect(Form1.Left,Form1.Top,bmp.Width+Form1.Left,bmp.height+Form1.Top);
Myrect2 :=Rect(0,0,bmp.Width,bmp.height);
DC := GetDC(0);
Canvas := TCanvas.Create;
Canvas.Handle := DC;
bmp.Canvas.CopyRect(MyRect2,Canvas,MyRect);
Clipboard.Assign(bmp);
if dlgSave1.Execute then
bmp.SaveToFile(dlgSave1.FileName + '.bmp');
Canvas.Free;
ReleaseDC(0,DC);
bmp.Free;


end;

end.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.