Article View: borland.public.cppbuilder.internet.web
Article #1668Re: TCppWebBrowser and CaptureThumbnail
From: Lapo Guidi
Date: Tue, 24 Aug 2004 14:20
Date: Tue, 24 Aug 2004 14:20
132 lines
4547 bytes
4547 bytes
Thanks Remy!
I had the same problem about IThumbnailCapture instance.
Well, what i would like to do is to save a page preview as jpeg of an HTML
page.
I asked about CreateThumbnail as last try.
I found these 2 Delphi codes snip but both seems not good for BCB++.
In the first I got an error because IHTMLDocument2 seems don't have a Body
property.
In the second I have JPEG, but all of them are 1600x1200 (like my screen
resolution).
Maybe you can help in that way.
------- first code ----------
var
Doc: IHTMLDocument2;
body: OleVariant;
begin
Doc := IHTMLDocument2(yourWebBrowser.Document);
body := Doc.Body; <<<------------- HERE THE
PROBLEM IHTMLDocument2 doesn't have Body property!
body.NoWrap := True;
{hide scrollbars}
body.Style.BorderStyle := 'none';
body.Scroll := 'no';
intWidth := body.ScrollWidth;
intHeight := body.ScrollHeight;
yourWebBrowser.Width := body.ScrollWidth;
yourWebBrowser.Height := body.ScrollHeight;
sourceDrawRect := Rect(0, 0, body.ScrollWidth, body.ScrollHeight);
sourceBitmap := TBitmap.Create;
try
sourceBitmap.Width := WebBrowser.Width;
sourceBitmap.Height := WebBrowser.Height;
WebBrowser.Document.QueryInterface(IViewObject, ViewObject);
if ViewObject <> nil then
try
ViewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, Self.Handle,
sourceBitmap.Canvas.Handle, @sourceDrawRect, nil, nil, 0);
finally
ViewObject._Release;
end;
sourceBitmap.SaveToFile(yourFileName);
finally
sourceBitmap.Free;
end;
end;
-------- second code ----------------
var
IDoc1: IHTMLDocument2;
Web: ShDocVW_TLB.IWebBrowser2;
tmpX, tmpY: Integer;
begin
with WebBrowser1 do
begin
Document.QueryInterface(IHTMLDocument2, iDoc1);
Web := ControlInterface;
tmpX := Height;
tmpY := Width;
TControl(WebBrowser1).Visible := Boolean(0);
Height := OleObject.Document.ParentWindow.Screen.Height;
Width := OleObject.Document.ParentWindow.Screen.Width;
generateJPEGfromBrowser(Web,'c:\test.jpg',Height, Width, Height, Width);
Height := tmpX;
Width := tmpY;
TControl(WebBrowser1).Visible := Boolean(1);
end;
end;
procedure generateJPEGfromBrowser(browser: iWebBrowser2; jpegFQFilename:
string;
srcHeight: Integer; srcWidth: Integer; tarHeight: Integer; tarWidth:
Integer);
var
sourceDrawRect: TRect;
targetDrawRect: TRect;
sourceBitmap: TBitmap;
targetBitmap: TBitmap;
jpeg: TJPEGImage;
viewObject: IViewObject;
begin
sourceBitmap := TBitmap.Create;
targetBitmap := TBitmap.Create;
jpeg := TJPEGImage.Create;
try
try
sourceDrawRect := Rect(0, 0, srcWidth, srcHeight);
sourceBitmap.Width := srcWidth;
sourceBitmap.Height := srcHeight;
viewObject := browser as IViewObject;
if viewObject = nil then
Exit;
OleCheck(viewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, Form1.Handle,
sourceBitmap.Canvas.Handle, @sourceDrawRect, nil, nil, 0));
// Resize the src bitmap to the target bitmap
targetDrawRect := Rect(0, 0, tarWidth, tarHeight);
targetBitmap.Height := tarHeight;
targetBitmap.Width := tarWidth;
targetBitmap.Canvas.StretchDraw(targetDrawRect, sourceBitmap);
// Create a JPEG from the Bitmap and save it
jpeg.Assign(targetBitmap);
jpeg.SaveToFile(jpegFQFilename);
finally
jpeg.Free;
sourceBitmap.Free;
targetBitmap.Free;
end;
except
// Error Code
end;
end;
------------------
Thanks for your time.
Sincerely,
Lapo
Technical Details
Message-ID:
<412b4ebf@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<412a9c86@newsgroups.borland.com> <412aedc2@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,9c51eda80d523333 X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Lapo Guidi" <lapoguidi@inwind.it> Newsgroups: borland.public.cppbuilder.internet.web References: <412a9c86@newsgroups.borland.com> <412aedc2@newsgroups.borland.com> Subject: Re: TCppWebBrowser and CaptureThumbnail Date: Tue, 24 Aug 2004 16:20:57 +0200 Lines: 134 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 82.49.68.193 Message-ID: <412b4ebf@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1093357247 82.49.68.193 (24 Aug 2004 07:20:47 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail