Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to copy WebBrowser image to bitmap


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Oct 28, 2015 7:08 AM Last Post By: Pete Fraser
Pete Fraser

Posts: 13
Registered: 1/13/01
How to copy WebBrowser image to bitmap  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 27, 2015 7:09 AM
I'm trying to get the contents of the TWebBrowser component as a rendered image and saving it to a file.
Can anyone point me in the right direction.
There is no canvas (that I can find) and I'm not sure how to use the interfaces. If anyone knows some docs that can help please let me know.
Cheers, Pete
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: How to copy WebBrowser image to bitmap  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 27, 2015 12:07 PM   in response to: Pete Fraser in response to: Pete Fraser
Pete Fraser wrote:

I'm trying to get the contents of the TWebBrowser component as a
rendered image and saving it to a file. Can anyone point me in the
right direction. There is no canvas (that I can find) and I'm not
sure how to use the interfaces. If anyone knows some docs that can
help please let me know. Cheers, Pete

You can only get the visible part of the web page using a canvas. If
the control has a window handle you can create a device context handle
for it using GetDC (API), and copy the visible content to a bitmap or
such using BitBlt. To get the browser to render the page (even the
parts scrolled out of view) to an image would require a printer driver
that renders to a bitmap, for instance. You could then just print the
browser content to that printer.

--
Peter Below
TeamB
Pete Fraser

Posts: 13
Registered: 1/13/01
Re: How to copy WebBrowser image to bitmap  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 28, 2015 7:07 AM   in response to: Peter Below in response to: Peter Below
Peter Below wrote:
Pete Fraser wrote:

I'm trying to get the contents of the TWebBrowser component as a
rendered image and saving it to a file. Can anyone point me in the
right direction. There is no canvas (that I can find) and I'm not
sure how to use the interfaces. If anyone knows some docs that can
help please let me know. Cheers, Pete

You can only get the visible part of the web page using a canvas. If
the control has a window handle you can create a device context handle
for it using GetDC (API), and copy the visible content to a bitmap or
such using BitBlt. To get the browser to render the page (even the
parts scrolled out of view) to an image would require a printer driver
that renders to a bitmap, for instance. You could then just print the
browser content to that printer.
So what I did was: (NOTE: C++ code)
TBitmap *pBitmap = new TBitmap();
pBitmap->SetSize(WebBrowser->Width, WebBrowser->Height);
pBitmap->PixelFormat = pf24bit;
HDC DC = GetDC(WebBrowser->Handle);
BitBlt(pBitmap->Canvas->Handle, 0, 0, 1920, 1080, DC, 0, 0,SRCCOPY);
pBitmap->SaveToFile("../../ScreenDump.jpg");
delete pBitmap;

and it worked correctly - Excellent. Thanks for your help
Of course it would be nice to create a full size image without rendering it to screen but that will have to come later...
If anyone has any ideas on that, please feel free to post them.

Rgds Pete
Pete Fraser

Posts: 13
Registered: 1/13/01
Re: How to copy WebBrowser image to bitmap  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 28, 2015 7:08 AM   in response to: Pete Fraser in response to: Pete Fraser
Thanks Pete, Pete
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02