Development :  K-Meleon Web Browser Forum
K-Meleon development related discussions. 
Capture html page as bitmap
Posted by: Jonx
Date: November 29, 2000 10:55AM

Hi,
I don't know who I can ask, so here I am smiling smiley
I was wondering if you would know a way of asking the browser
to output an html page view into a bitmap or any image type.
This would be used to make some fast previews of a series of
sites in my favorites handling tool. It must work without the webbrowser
beeing visible on screen.
You see what I mean ? Let's say I create a webbrowser in the background.
Without showing it I ask him to browse to an url...
After that I ask the browser to paint the the html page to a bitmap or else.
A sort of paintTo...
Do you have any idea of how this could be done ? If the method would be
compatible with IE, would be even more cool.
If you help me out on this I will make you a very nice favorite handling tool.
To get a sneak preview take a look here of an older version:
http:\\www.happytocode.com\projects\www5.jpg
http:\\www.happytocode.com\projects\www6.jpg
Thank you very much for your help...
John.

Options: ReplyQuote
RE: Capture html page as bitmap
Posted by: suppafly
Date: January 05, 2001 06:54PM

doesnt alt-prntscr already make a decent screen shot of the active window?

Options: ReplyQuote
RE: Capture html page as bitmap
Posted by: Jonx
Date: January 06, 2001 12:28AM

Wow,
Thanks for commenting on this...
But look, what you suggest is working, but not for what I want to do...

It's working for the active windows, this means that I will not be able to
do something else while catching stuff...
And most of all, it does not work for a hidden windows...
So...thanks for your time, I appreciate the effort.
Bests regards.
John.

But I found how to do since the time. Some cool guys did know some links
others agreed to share there great knowledge with me.
So here it is :
Of course it's delphi stuff smiling smiley

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, Application.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);
//makeFileWriteable(jpegFQFilename);
jpeg.SaveToFile(jpegFQFilename);
finally
jpeg.free;
sourceBitmap.free;
targetBitmap.free;
end;
except
// Error Code
end;
end;

procedure TFRM_tree_import.Button2Click(Sender: TObject);
var
ViewObject: IViewObject;
sourceDrawRect: TRect;
begin
if EmbeddedWB1.Document <> nil then
try
EmbeddedWB1.Document.QueryInterface(IViewObject, ViewObject);
if ViewObject <> nil then
try
sourceDrawRect := Rect(0, 0, EmbeddedWB1.Width, EmbeddedWB1.Height);
OleCheck(ViewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, Self.Handle,
image1.Canvas.Handle, @sourceDrawRect, nil, nil, 0));
finally
ViewObject._Release;
end;
except end;
end;


Options: ReplyQuote
RE: Capture html page as bitmap
Posted by: Abhi
Date: September 14, 2003 03:42AM

Hi,

I am trying to achieve what you are trying to achieve using C++. Please provide me some useful pointers in understanding the solution. Basically, I wish to access the rendered HTML page by Gecko as a bitmap in my c++ code.

Thank you.
Abhi

Options: ReplyQuote


K-Meleon forum is powered by Phorum.