Delphi 从TWebBrowser到TPicture的图像
如何将已在TWebBrowser中下载的图像获取到TPicture,而无需将其复制到剪贴板或查看缓存内容。好的,我制作了示例,最后一个答案是: 首次使用此函数按Id获取图像:Delphi 从TWebBrowser到TPicture的图像,delphi,winapi,rendering,delphi-xe2,twebbrowser,Delphi,Winapi,Rendering,Delphi Xe2,Twebbrowser,如何将已在TWebBrowser中下载的图像获取到TPicture,而无需将其复制到剪贴板或查看缓存内容。好的,我制作了示例,最后一个答案是: 首次使用此函数按Id获取图像: function GetImgElementById(const Doc: IDispatch; const id : string): IHTMLImgElement; var Document: IHTMLDocument2; // IHTMLDocument2 interface of Doc Bod
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;
不要忘记“MSHTML”单元 好的,我做了一个样本,最后一个回答是: 首次使用此函数按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;
不要忘记“MSHTML”单元 如果你只想从网上下载一张图片(或任何其他文件),那很容易。(比使用TWebBrowser要容易得多)。“但我想你有你的理由吗?”安德烈亚斯雷杰布兰德我更新了我的问题。我找到了一个解决办法。但需要有人翻译。
DrawToDC
已被弃用,请参阅。还有一个问题:.@LURD并不是他想要呈现整个页面的问题。这个问题说明了不推荐使用的DrawToDC
的问题。如果您只想从web下载一个图像(或任何其他文件),这非常简单。(比使用TWebBrowser要容易得多)。“但我想你有你的理由吗?”安德烈亚斯雷杰布兰德我更新了我的问题。我找到了一个解决办法。但需要有人翻译。DrawToDC
已被弃用,请参阅。还有一个问题:.@LURD不是他想要呈现整个页面的问题。这个问题说明了弃用的DrawToDC
的问题。是否可以基于src属性修改函数?tag=ansicontainstr('imagehostname.com')如果函数中的tag.getAttribute('src')可以用于indy IdHttp,则可以获取信息?不,您不能以这种方式使用direct,必须将结果传递给TWebBrowser
。是否可以基于src属性修改函数?tag=ansicontainstr('imagehostname.com')您可以在if函数中使用tag.getAttribute('src')获取信息这可以用于indy IdHttp吗?不,您不能以这种方式使用direct,您必须将结果传递给TWebBrowser
。