简体   繁体   English

从TWebBrowser到TPicture的图像

[英]Image from TWebBrowser to TPicture

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

ok i made sample with last answer to you : 好吧,我向您提供了最后答案的样品:

fisrt get image with this function by Id : fisrt通过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;

after you can use it : 在您可以使用它之后:

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;

dont forget "MSHTML" unit ; 不要忘记“ MSHTML”单元;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM