473,387 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Screen capture control using WebBrowser control and GDI+ in a web app

I'm trying to write a control that will take a screen capture of a
particular website when a user submits a form in a web application; one
of the form fields is for a URL - the control needs to get an image of
that web site so that it can be displayed later as a thumbnail image.

I have code for taking a normal screen capture using GDI+ which works
fine. What I am now trying to do is to modify it so the screen capture
is of a remote website rather than of my PC. To attempt to do this I am
using the .NET WebBrowser control to load the website URL into.

The main bit of code is:
// The method that is called from the ASPX page when the form is
submitted
public static void newxcap2()
{
WebBrowser m_browser = new WebBrowser();
m_browser.Visible = false;
m_browser.DocumentCompleted += new
WebBrowserDocumentCompletedEventHandler(GetScreenC apture);
m_browser.Navigate(m_browser.Url = new
Uri("http://www.bbc.co.uk
}

public static void GetScreenCapture(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
Graphics _g = ((WebBrowser)sender).CreateGraphics();
System.IntPtr desktopDC = GetDC(System.IntPtr.Zero);
Image bm = new Bitmap(300, 300, _g);
Graphics g = Graphics.FromImage(bm);
System.IntPtr bmDC = g.GetHdc();
BitBlt(bmDC, 0, 0, bm.Width,bm.Height, desktopDC, 0, 0,
0x00CC0020 /*SRCCOPY*/);
ReleaseDC(System.IntPtr.Zero, desktopDC);
g.ReleaseHdc(bmDC);
g.Dispose();
bm.Save(@"C:\Documents and
Settings\JP\Desktop\xCapImage.bmp");
}

Having tinkered around with it quite a bit the most I can make it do is
to generate a blank image, other attempts have resulted in various
errors.

Am I on the right track in general here with the use of the WebBrowser
control (to in effect load a webpage behind the scenes) or am I
approaching this in the wrong way?
Thanks

James

Jan 7 '07 #1
1 4478
Uhm I'm surprised you're even getting that far. I suspect the Web Browser
requires a hosting container to work with a window. I don't think it will
render unless there's a Windows event loop to refresh the display area...
You can check and see if that's the issue by creating a form and then from
within ASP.NET fire that form with a full Application.Run event loop. That
*might* work better, but even then this might not work. Remember ASP.NET
runs as a service in a system context not on the desktop.

ASP.NET is not really a good way to do this.Aside from the security issues,
this seems like a task for a WinForm application...

+++ Rick ---

--
Rick Strahl
West Wind Technologies
www.west-wind.com/weblog

"JP2006" <ja********@gmail.comwrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
I'm trying to write a control that will take a screen capture of a
particular website when a user submits a form in a web application; one
of the form fields is for a URL - the control needs to get an image of
that web site so that it can be displayed later as a thumbnail image.

I have code for taking a normal screen capture using GDI+ which works
fine. What I am now trying to do is to modify it so the screen capture
is of a remote website rather than of my PC. To attempt to do this I am
using the .NET WebBrowser control to load the website URL into.

The main bit of code is:
// The method that is called from the ASPX page when the form is
submitted
public static void newxcap2()
{
WebBrowser m_browser = new WebBrowser();
m_browser.Visible = false;
m_browser.DocumentCompleted += new
WebBrowserDocumentCompletedEventHandler(GetScreenC apture);
m_browser.Navigate(m_browser.Url = new
Uri("http://www.bbc.co.uk
}

public static void GetScreenCapture(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
Graphics _g = ((WebBrowser)sender).CreateGraphics();
System.IntPtr desktopDC = GetDC(System.IntPtr.Zero);
Image bm = new Bitmap(300, 300, _g);
Graphics g = Graphics.FromImage(bm);
System.IntPtr bmDC = g.GetHdc();
BitBlt(bmDC, 0, 0, bm.Width,bm.Height, desktopDC, 0, 0,
0x00CC0020 /*SRCCOPY*/);
ReleaseDC(System.IntPtr.Zero, desktopDC);
g.ReleaseHdc(bmDC);
g.Dispose();
bm.Save(@"C:\Documents and
Settings\JP\Desktop\xCapImage.bmp");
}

Having tinkered around with it quite a bit the most I can make it do is
to generate a blank image, other attempts have resulted in various
errors.

Am I on the right track in general here with the use of the WebBrowser
control (to in effect load a webpage behind the scenes) or am I
approaching this in the wrong way?
Thanks

James
Jan 7 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: redneon | last post by:
Is it possible to draw directly to the screen using the .net libraries? I thought that it might be possible with GDI+ but I can't find out how to do it anywhere. A part of me suspects I may have to...
5
by: TerryWilson | last post by:
I am developing a web based service tool using asp.net that we will distribute with our product. This service tool will be used for remotely configuring the product, problem determination, etc. ...
0
by: Fabio R. | last post by:
With GDI+ I've made a little winform app to capture a webpage snapshot, using the CreateGraphic method of the Webbrowser control. Everything works fine in winform, but I need (by user input) URL...
1
by: Jody Gelowitz | last post by:
I have seen some examples of how to capture a color from a point on screen using C#, but haven't come across anything with VB.NET. Is this possible under VB.NET? I know that I will need to use...
4
by: gregory_may | last post by:
http://www.geocities.com/krishnapg/screencap.html This article gives a pretty good background on various ways to capture the screen. I have some code to do it the GDI way below, but I cant...
2
by: Eddie Dunn | last post by:
I have one here that I cannot find anything on in my searching. I am implementing a screen capture functionality into my Visual Basic ..NET application. The code I am using calls the bitblt...
3
by: Nikolay Petrov | last post by:
I want to make a screen magnifier which follows the mouse pointer. Is it possible using the Framework or I should use WinAPI?
0
by: Vin | last post by:
The .Net 2.0's webbrowser is neat and pretty. But I am not able to capture Key events when the focus is on the webbrowser control in my winform. Options tried. 1. Wrote a class which extends this...
2
by: =?Utf-8?B?c25naWxi?= | last post by:
The WebBrowser control is described as exposing numerous public mouse events. See: http://msdn2.microsoft.com/en-us/library/ayestehw.aspx. many of the event are described as: "This event is not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.