zoukankan      html  css  js  c++  java
  • CaptureComponentToBmp

    CaptureComponentToBmp

    代码
    {*******************************************************}
    { }
    { Created By: Ming.z }
    { Creation Date 2010-12-28 }
    { }
    {*******************************************************}

    unit Unit1;

    interface

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

    type
    TForm1
    = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Panel1: TPanel;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure CaptureComponentToBmp(aControl:TWinControl;const savePath:String);
    var
    can: TCanvas;
    bmp: TBitmap;
    begin
    can :
    = TCanvas.Create;
    bmp :
    = TBitmap.Create;
    try
    bmp.Width :
    = aControl.Width;
    bmp.Height :
    = aControl.Height;
    can.Handle :
    = GetDC(aControl.Handle);
    bmp.Canvas.CopyRect(aControl.ClientRect,can,aControl.ClientRect);
    bmp.SaveToFile(savePath);
    finally
    bmp.Free;
    can.Free;
    end;
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    CaptureComponentToBmp(Memo1,
    'E:\Memo1.bmp');
    ShowMessage(
    'OK');
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    begin
    CaptureComponentToBmp(Panel1,
    'E:\Panel1.bmp');
    ShowMessage(
    'OK');
    end;

    end.

  • 相关阅读:
    [LeetCode] 143. 重排链表
    [LeetCode] 342. 4的幂
    [LeetCode] 1744. 你能在你最喜欢的那天吃到你最喜欢的糖果吗?
    [LeetCode] 148. 排序链表
    [LeetCode] 525. 连续数组
    [LeetCode] 160. 相交链表
    [LeetCode] 134. 加油站
    [LeetCode] 474. 一和零
    CentOS 升级 OpenSSH
    AWS 证书取消挂靠
  • 原文地址:https://www.cnblogs.com/Jekhn/p/1918704.html
Copyright © 2011-2022 走看看