zoukankan      html  css  js  c++  java
  • Delphi实现截屏存盘的方法

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,jpeg;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure ScreenCap(LeftPos,TopPos,RightPos,BottomPos:integer);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      ScreenCap(0,0,Screen.Width,Screen.Height);
    end;
    procedure TForm1.ScreenCap(LeftPos,TopPos,RightPos,BottomPos:integer);
    var
     RectWidth,RectHeight:integer;
     SourceDC,DestDC,Bhandle:integer;
     Bitmap:TBitmap;
     MyJpeg: TJpegImage;
     Stream:TMemoryStream;
    begin
     MyJpeg:= TJpegImage.Create;
     RectWidth:=RightPos-LeftPos;
     RectHeight:=BottomPos-TopPos;
     SourceDC:=CreateDC('DISPLAY','','',nil);
     DestDC:=CreateCompatibleDC(SourceDC);
     Bhandle:=CreateCompatibleBitmap(SourceDC,
     RectWidth,RectHeight);
     SelectObject(DestDC,Bhandle);
     BitBlt(DestDC,0,0,RectWidth,RectHeight,SourceDC,
     LeftPos,TopPos,SRCCOPY);
     Bitmap:=TBitmap.Create;
     Bitmap.Handle:=BHandle;
     Stream := TMemoryStream.Create;
     Bitmap.SaveToStream(Stream);
     Stream.Free;
     try
      MyJpeg.Assign(Bitmap);
      MyJpeg.CompressionQuality:=70;
      MyJpeg.Compress;
      MyJpeg.SaveToFile('C:MyJPEGImage.JPG');
     finally
      MyJpeg.Free;
      Bitmap.Free;
      DeleteDC(DestDC);
      ReleaseDC(Bhandle,SourceDC);
     end;
    end;
    end.
    

      

  • 相关阅读:
    hdu 1520(简单树形dp)
    hdu 1561(树形dp)
    hdu 2809(状压dp)
    hdu 2196(求树上每个节点到树上其他节点的最远距离)
    hdu 4003(树形dp)
    hdu 3899(树形dp)
    hdu 4714(树形dp)
    hdu 3905(dp)
    Linux mariadb(Mysql)的主从复制架构
    面向对象静态变量代码题
  • 原文地址:https://www.cnblogs.com/tc310/p/5244055.html
Copyright © 2011-2022 走看看