[Delphi] WebBrowser i PrintScreen

0

Witam!

Szukam już od jakiegoś czasu sposobu na wykonanie print screena całej strony wczytanej do webbrowsera. Czy jest na to jakiś sposób?

Pozdrawiam

0

Szukam już od jakiegoś czasu (...)

a ja szukałem całe 2 minuty :)
http://delphi.about.com/od/vclusing/a/wb_scren_shot.htm

0
papudrun napisał(a)

a ja szukałem całe 2 minuty :)
http://delphi.about.com/od/vclusing/a/wb_scren_shot.htm

zauwaz ze "misiakufal" zapytal o zrobienia screena calej strony, a z tego co widze w kodzie:

  bitmap.Height := wb.Height;
  bitmap.Width := wb.Width;

...to na screenie bedzie widac tylko to co w webbrowserze a nie cala strone.

mozesz po prostu zrobic screena, przewinac, zrobic drugiego itd.. potem polaczyc bitmapy.

0

hmm... no tak jak Cimak napisał, po części ta procedura działa.. tylko robi screena o wymiarach wb. W takim razie pytanie jest takie: jak odczytac w wb wysokość strony (wtedy dałbym wb.height:=wb.page_height)? Szerokość mnie nie interesuje, bo będzie wpisywana przez uzytkownika. Na upartego mógłbym ustawić wb.height na np 30000, zrobić screena tą procedurą a potem bitmape jechac scaline od dołu i sprawdzać kiedy zaczną się pojawiać jakieś elementy. Jak sie coś pojawi to w tym miejscu "obciać". Tylko problem pojawia się jak ktoś ustawi np na tło jakiś powielajacy się obrazek...

0

na bank da sie wyciagnac informacje o wysokosci strony.
jakies document.height albo cos takiego. patrzyles na googlach?
wpisz: delphi webbrowser page height, widze ze znalazlo jakies kody gotowe do robienia screena. moze tego wlasnie szukasz..
http://delphi.about.com/od/vclusing/a/wb_scren_shot.htm
http://www.delphi3000.com/articles/article_4132.asp?SK=

0

Znalazłem taką funkcję. Spróbuj tego:

function GetDocumentSize(Browser: TWebBrowser): TPoint;
var pElement: IHTMLElement2;
begin

// Get the browser body element interface
if Succeeded(GetBrowserElement(Browser, pElement)) then
begin
// Resource protection
try
// Set result size
result:=Point(pElement.ScrollWidth, pElement.ScrollHeight);
finally
// Release the interface
pElement:=nil;
end;
end

end;
0

papudrun [browar] [browar] [browar]
Wielkie dzięki:)

Oto działajacy kod:

function GetBrowserElement(Browser: TWebBrowser; out Element: IHTMLElement2): HResult;
var pDoc: IHTMLDocument2;
pElemParent: IHTMLElement;
pElement: IHTMLElement;
pElement2: IHTMLElement2;
begin

// Check browser document
if Assigned(Browser.Document) then
begin
// QI for document 2 interface
result:=Browser.Document.QueryInterface(IHTMLDocument2, pDoc);
// Check result
if Succeeded(result) then
begin
// Resource protection
try
// Check document body
if Assigned(pDoc.Body) then
begin
// QI for body element
result:=pDoc.Body.QueryInterface(IHTMLElement, pElement);
// Check result
if Succeeded(result) then
begin
// Resource protection
try
// Get parent element
pElemParent:=pElement.parentElement;
// Check parent
if Assigned(pElemParent) then
begin
// Resource protection
try
// Get the element 2 interface
if Succeeded(pElemParent.QueryInterface(IHTMLElement2 , pElement2)) then
begin
// Check parent interface for zero client width or height
if (pElement2.clientWidth = 0) or (pElement2.clientHeight = 0) then
// QI for element 2 interface
result:=pElement.QueryInterface(IHTMLElement2, Element)
else
// We have the element we are after
Element:=pElement2;
end
else
// QI for element 2 interface
result:=pElement.QueryInterface(IHTMLElement2, Element);
finally
// Release the interface
pElemParent:=nil;
end;
end
else
// Return nearest COM error
result:=E_NOINTERFACE;
finally
// Release the interface
pElement:=nil;
end;
end;
end
else
// Return nearest COM error
result:=E_NOINTERFACE;
finally
// Release the interface
pDoc:=nil;
end;
end;
end
else
// Return nearest COM error
result:=E_NOINTERFACE;

end;

function GetDocumentSize(Browser: TWebBrowser): TPoint;
var pElement: IHTMLElement2;
begin

// Get the browser body element interface
if Succeeded(GetBrowserElement(Browser, pElement)) then
begin
// Resource protection
try
// Set result size
result:=Point(pElement.ScrollWidth, pElement.ScrollHeight);
finally
// Release the interface
pElement:=nil;
end;
end

end;

Używamy tak:

var punkt:TPoint;
Punkt:=GetDocumentSize(WebBrowser1);

0

aaaaaaa :-[ formatuj kod [!!!]

0

przekleiłem na szybko z linka podanego przez papudrun'a, a tam nie było formatowania

0

Jak nie chce się Wam mozolnie formatować kodu to skorzystajcie z programu, ktory nieco
poprawiłem z oryginalnych źródel i wrzuciłem na http://www.mediafire.com/?0btnnnuywyn

1 użytkowników online, w tym zalogowanych: 0, gości: 1