Einzelnen Beitrag anzeigen

TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.070 Beiträge
 
Delphi 10.4 Sydney
 
#2

AW: Screeshot TWebbrowser

  Alt 21. Dez 2021, 12:56
Folgender Codeschnipsel funktioniert bei mir:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.OleCtrls, SHDocVw, Vcl.StdCtrls, Winapi.ActiveX;

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

function GetIEBitmap(IEDoc: IWebBrowser2): TBitmap;
var
  ViewObject: IViewObject;
  DrawRect: TRect;
begin
  Result := TBitmap.Create;
  Result.Width := IEDoc.Width;
  Result.Height := IEDoc.Height;
  if IEDoc.Document <> nil then
  begin
    IEDoc.Document.QueryInterface(IViewObject, ViewObject);
    if ViewObject <> nil then
    try
      DrawRect := Rect(0, 0, Result.Width, Result.Height);
      ViewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, Form1.Handle,
        Result.Canvas.Handle, @DrawRect, nil, nil, 0);
    finally
      ViewObject._Release;
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  IE: IWebbrowser2;
  MyBitmap: TBitmap;
begin
  IE := Webbrowser1.DefaultInterface as IWebBrowser2;
  MyBitmap := GetIEBitmap(IE);
  MyBitmap.SaveToFile('C:\Temp\MyScreenshot.bmp');
  MyBitmap.Free;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  WebBrowser1.Navigate('http://tools.geofabrik.de/map/#18/50.4720/7.4568&type=Geofabrik_Standard');
end;

end.
GetIEBitmap habe ich hier gefunden: https://www.delphipraxis.net/69655-w...creenshot.html
  Mit Zitat antworten Zitat