delphi 取控件下的图象


本文整理自网络,侵删。

 
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, jpeg;
 
type
  TForm1 = class(TForm)
    pnl1: TPanel;
    pnl2: TPanel;
    img1: TImage;
    img2: TImage;
    btn1: TButton;
    procedure btn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.btn1Click(Sender: TObject);
   var
    DC : HDC;
    SaveIndex : HDC;
    Position: TPoint;
    Control : TWinControl ;
    Buf : TBitmap;
    w:integer;
begin
    Buf := TBitmap.Create();
    Buf.PixelFormat := pfDevice;
    Buf.Width := btn1.Width;
    Buf.Height := btn1.Height;
 
     Control:= btn1;
   if Control.Parent <> nil then
    begin
{$R-}
        DC := Buf.Canvas.Handle;
        SaveIndex := SaveDC(DC);
        GetViewportOrgEx(DC, Position);
        SetViewportOrgEx(DC, Position.X - Control.Left, Position.Y - Control.Top, nil);
        IntersectClipRect(DC, 0, 0, Control.Parent.ClientWidth, Control.Parent.ClientHeight);
        Control.Parent.Perform(WM_ERASEBKGND, DC, 0);
        Control.Parent.Perform(WM_PAINT, DC, 0);
        RestoreDC(DC, SaveIndex);
         w:=Buf.Width;
        self.img1.Picture.Graphic:=Buf;
{$R+}
    end;
end;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
    self.btn1.Parent:=self.pnl1;
end;
 
end.
 

相关阅读 >>

Delphi远程线程注入获取qq密码

Delphi 获得网页乱码

Delphi中使用flash控件

Delphi 能否把.txt文件的数据导入到access数据库中

Delphi tpath

Delphi图像匹配算法

Delphi idftp 详解

Delphi 深入了解unigui hyperserver

Delphi opendialog文件过滤类型

Delphi idtcp上传文件

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...