zoukankan      html  css  js  c++  java
  • 获取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

  • 相关阅读:
    进程 线程 协程
    TCP的滑动窗口和网络拥塞控制
    Golang中函数结构体,将函数转换为接口
    go的调度 与 go 的GC
    未来程序员这个工种会如何进化与“35岁之殇”的思考
    golang 实现 LRU
    golang 单例模式实现
    内存泄露及内存溢出,解决方案
    Jvm调优参数
    HttpUtil
  • 原文地址:https://www.cnblogs.com/findumars/p/3493599.html
Copyright © 2011-2022 走看看