Delphi 如何提取WebBrowser里的图片?

procedure DomImg2Image(src:string;wb:TWebBrowser;img:TImage);
var
  i:Integer;
  rang:IHTMLControlRange;
begin
  for i:=0 to IHTMLDocument2(wb.Document).images.length-1 do
    if Pos(src,(IHTMLDocument2(wb.Document).images.item(i,EmptyParam)as
      IHTMLElement).getAttribute('src',0))>0 then
    begin
      rang:=((IHTMLDocument2(wb.Document).body as HTMLBody).createControlRange)as
        IHTMLControlRange;
      rang.add(IHTMLDocument2(wb.Document).images.item(i,EmptyParam)as
        IHTMLControlElement);
      rang.execCommand('Copy',False,0);
      try img.Picture.Assign(ClipBoard)except end;
      break;
    end;
end;

procedure TForm1.WebBrowser1DocumentComplete(Sender:TObject;
const pDisp:IDispatch;var URL:OleVariant);
begin
  DomImg2Image('checkcode?',TWebBrowser(Sender),Image1);
end;
必须先uses ActiveX
initialization
OleInitialize(nil);
finalization
OleUninitialize;

//多看几篇就懂了,关键还是这个接口 IHTMLControlElement

转自:http://zhidao.baidu.com/question/95550405.html

posted @ 2012-01-08 11:54  stma  阅读(1647)  评论(0)    收藏  举报