472,784 Members | 779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 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 4428
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.