Thema: Delphi Webbrowser Screenshot

Einzelnen Beitrag anzeigen

Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#1

Webbrowser Screenshot

  Alt 18. Mai 2006, 07:20
Hallo,

Ich möchte aus von einem beliebigen IE Fenster ein Vorschaubildchen erstellen.
Das funktioniert bestens mit der Funktion GetIEBitmap(), wenn ich einen TWebbrowser angebe.

Wenn ich jedoch auf ein IHTMLDocument2 von einem IE Fenster zugreife, gibt's am Ende von
Button1Click eine AV (Siehe auch Screenshot, asm Code)

Zitat:
---------------------------
Debugger Exception Notification
---------------------------
Project SaveIE.exe raised exception class EAccessViolation with message 'Access violation at address FEEEFEEE. Read of address FEEEFEEE'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
Hat jemand eine Idee warum? Was müsste man ändern, damit's keine AV gibt?

Delphi-Quellcode:
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;
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  IE: IWebbrowser2;
  targetBitmap: TBitmap;
begin
  IE := Webbrowser1.DefaultInterface as IWebBrowser2;
  targetBitmap := GetIEBitmap(IE);
  try
    ImgPreview.Picture.Bitmap.Assign(targetBitmap);
  finally
    targetBitmap.Free;
  end;
end;
Miniaturansicht angehängter Grafiken
error_201.jpg  
Thomas
  Mit Zitat antworten Zitat