views:

272

answers:

2

Hi,

i have a web-browser control, through this i am able to navigate diffrent sites. how to take the bitmap of the site we visit.

Thanks GrabIt

A: 
  1. Get the Rectangle occupied by the browser control
  2. Create a DC for the screen: screen=GetDC(NULL)
  3. Create a compatible DC: memDC=CreateCompatibleDC(screen)
  4. Create a compatible bitmap: bmp=CreateCompatibleBitmap(screen, rect);
  5. select the compatible bitmap into the compatible DC SelectObject(memDC, bmp)
  6. BitBlt from the screenDC to the compatible DC

The bitmap you created should now contain an image of that area of the screen.

Jerry Coffin
What if, as will almost always be the case on a mobile device, the page requires scrolling? This isn't going to get the entire page. Your suggestion is also C, not C#.
ctacke
i want to get the off-screen content also..
Shadow
@GrabIt:To get the off-screen content, you're probably going to have to scroll, and re-grab. I'm not at all sure that the browser control (necessarily) keeps a fully-rendered bitmap of the whole page anywhere. @ctacke:it's Win32 API, in whatever language you prefer -- if he wants to stay inside of .NET and not use the API directly, he should remove the [Win32] tag.
Jerry Coffin
A: 

Something like this will work -

Bitmap bitmap = new Bitmap(webBrowser1.Width, webBrowser1.Height);
Graphics g = Graphics.FromImage(bitmap);
g.CopyFromScreen(webBrowser1.PointToScreen(webBrowser1.Location), new Point(), webBrowser1.Size);
bitmap.Save(@"c:\\browser.jpg", ImageFormat.Jpeg);
bitmap.Dispose();
PaulB
CopyFromScreen is not supported on the Compact Framework.
tomlog
Note to self - examine the tags ...
PaulB
@tomlog: GraphicsEx in the SDF does have it though.
ctacke