• 获取exe文件窗口抓图,将memo转化为JPG输出


    unit Unit1;

    interface

    uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Data.DB, Data.Win.ADODB;

    type
    TForm1 = class(TForm)
    Button1: TButton;
    ADOTable1: TADOTable;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    function PrintWindow(SourceWindow: hwnd; Destination: hdc; nFlags: cardinal): bool; stdcall; external 'user32.dll' name 'PrintWindow';

    procedure TForm1.Button1Click(Sender: TObject);
    var
    bmp: TBitmap;
    wnd: cardinal;
    rec: TRect;
    begin
    wnd := FindWindow(nil, 'Calculatrice'); // 查找窗口句柄,这里用计算器演示
    GetWindowRect(wnd, rec); // 获取到计算器窗口的举行
    bmp := TBitmap.Create;
    try
    bmp.Width := rec.Right - rec.Left;
    bmp.Height := rec.Bottom - rec.Top;
    bmp.PixelFormat := pf24bit;
    PrintWindow(wnd, bmp.Canvas.Handle, 0);
    bmp.SaveToFile('c:cc.bmp');
    finally
    bmp.Free;
    end;
    end;

    end.

    http://www.cnblogs.com/wxy8/archive/2011/01/24/1943045.html

    unit unit1;

    interface

    uses
      Windows, Messages, SysUtils, Graphics, Controls, Forms, StdCtrls,
      Classes;

    type
      TForm1 = class(TForm)
        Button1: TButton;
        Memo1: TMemo;

        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation
    uses jpeg;
    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    var
      vBitmap: TBitmap;
      vJpegImage: TJpegImage;
      vOldHeight: Integer;
    begin
      Canvas.Font.Assign(Memo1.Font);
      vOldHeight := Memo1.Height;
      Memo1.ClientHeight := Canvas.TextHeight('|') * Memo1.Lines.Count + 2;
      vBitmap := TBitmap.Create;
      vJpegImage := TJpegImage.Create;
      try
        vBitmap.Height := Memo1.ClientHeight;
        vBitmap.Width := Memo1.ClientWidth;
        Memo1.PaintTo(vBitmap.Canvas, -2, -2);
        vJpegImage.Assign(vBitmap);
        vJpegImage.CompressionQuality := 75;
        vJpegImage.Compress;
        vJpegImage.SaveToFile('输出.jpg');
          //    Image1.Picture.Graphic   :=   vJpegImage;
      finally
        vBitmap.Free;
        Memo1.Height := vOldHeight;
      end;

    end;

    http://www.cnblogs.com/wxy8/archive/2011/01/13/1934477.html

  • 相关阅读:
    板子们~缓慢更新
    Hello World!
    [SHOI2008]堵塞的交通traffic
    [JSOI2008]最大数
    [SCOI2005]扫雷
    [HAOI2007]上升序列
    [HAOI2007]理想的正方形
    [SCOI2003]字符串折叠
    [HAOI2008]移动玩具
    [BJOI2006]狼抓兔子
  • 原文地址:https://www.cnblogs.com/findumars/p/3493599.html
Copyright © 2020-2023  润新知