从TWebBrowser到TPicture的图像 [英] Image from TWebBrowser to TPicture

查看:159
本文介绍了从TWebBrowser到TPicture的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取已经在TWebBrowser中下载到TPicture而不将其复制到剪贴板或查找缓存内容的图像。

How to get an image that has been downloaded in TWebBrowser to a TPicture without copying it to clipboard or looking in to cache contents.

推荐答案

好,我用最后一个答案做了样本:

ok i made sample with last answer to you :

fisrt通过Id获取图像:

fisrt get image with this function by Id :

function GetImgElementById(const Doc: IDispatch; const id : string): IHTMLImgElement;
var
  Document: IHTMLDocument2;     // IHTMLDocument2 interface of Doc
  Body: IHTMLElement2;          // document body element
  Tags: IHTMLElementCollection; // all tags in document body
  Tag: IHTMLElement;            // a tag in document body
  I: Integer;                   // loops thru tags in document body
begin

  Result :=nil ;
  // Check for valid document: require IHTMLDocument2 interface to it
  if not Supports(Doc, IHTMLDocument2, Document) then
    raise Exception.Create('Invalid HTML document');
  // Check for valid body element: require IHTMLElement2 interface to it
  if not Supports(Document.body, IHTMLElement2, Body) then
    raise Exception.Create('Can''t find <body> element');
  // Get all tags in body element ('*' => any tag name)
  Tags := Body.getElementsByTagName('img');
  // Scan through all tags in body
  for I := 0 to Pred(Tags.length) do
  begin
    // Get reference to a tag
    Tag := Tags.item(I, EmptyParam) as IHTMLElement;
    // Check tag's id and return it if id matches
    if AnsiSameText(Tag.id, id) then
    begin
      Result := Tag as IHTMLImgElement ;
      Break;
    end;
  end;
end;

您可以使用它:

var
  img : IHTMLImgElement ;
  rnd : IHTMLElementRender ;
begin
  //
  img := GetImgElementById(wb1.Document,'imgid');
  // img1 is TImage
  img1.Height := img.height ;
  img1.Width := img.width ;
  rnd := img as IHTMLElementRender ;
  rnd.DrawToDC(img1.Canvas.Handle);
end;

不要忘记MSHTML单位;

dont forget "MSHTML" unit ;

这篇关于从TWebBrowser到TPicture的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆