Как получить изображение, загруженное в TWebBrowser, на TPicture, не копируя его в буфер обмена и не просматривая содержимое кеша.
Изображение из TWebBrowser в TPicture
Ответы (1)
хорошо, я сделал образец с последним ответом вам:
сначала получить изображение с помощью этой функции по идентификатору:
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»;
person
A1Gard
schedule
18.11.2012
Можно ли изменить функцию на основе атрибута src? tag=AnsiContainsStr('imagehostname.com') ‹img id=Id style=display: inline; ширина: 218 пикселей; высота: 48 пикселей; src=imagehostname.com?u=235235235235235›
- person ; 19.11.2012
вы можете получить информацию с помощью Tag.getAttribute('src') в функции if
- person A1Gard; 19.11.2012
Можно ли это использовать с indy IdHttp?
- person Ouerghi Yassine; 15.06.2013
Нет, вы не можете использовать direct таким образом, вы должны передать результат
TWebBrowser
.
- person A1Gard; 21.06.2013
TWebBrowser
). Но я полагаю, у вас есть свои причины? - person Andreas Rejbrand   schedule 19.11.2012DrawToDC
устарел, см. MSDN DOC. Также этот вопрос SO: Как отобразить WebBrowser в контексте устройства?. - person LU RD   schedule 19.11.2012DrawToDC
. - person LU RD   schedule 19.11.2012