2010. július 23., péntek

How to capture the image in a TWebBrowser


How to capture the image in a TWebBrowser


Here's how: It involves grabbing the Internet Explorer_Server window handle, then getting the device context of that window, then assigning the DC to a new TCanvas, and finally, calling the appropriate VCL methods.

procedure TForm1.Button1Click(Sender: TObject);
  ShellDocObjectView: HWND;
  InternetExplorerServer: HWND;
  WebCanvas: TCanvas;
  ShellDocObjectView := FindWindowEx(WebBrowser1.Handle, 0, 'Shell DocObject View', nil);
  InternetExplorerServer := FindWindowEx(ShellDocObjectView, 0, 'Internet Explorer_Server', nil);
  WebCanvas := TCanvas.Create;
  WebCanvas.Handle := GetDC(InternetExplorerServer);
  InvalidateRect(InternetExplorerServer, nil, True);
    Image1.Canvas.CopyRect(Rect(0, 0, Image1.Width, Image1.Height), WebCanvas,
      Rect(0, 0, WebBrowser1.Width, WebBrowser1.Height));
    ReleaseDC(InternetExplorerServer, WebCanvas.Handle);
    WebCanvas.Handle := 0;

Likewise, you can call  Image1.Picture.Bitmap.SaveToFile('C:\My.bmp') to save the bitmap image
to a file.

Nincsenek megjegyzések:

Megjegyzés küldése