473,480 Members | 2,347 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem in taking screenshot of webpages

31 New Member
Hello,

I want screenshot of website by passing url. I used the DrawtoBitmap method of webbrowser but it is not working properly. It gives empty images. I want screenshot of websites which i passed in loop.

Expand|Select|Wrap|Line Numbers
  1.  arrayList arrURL; 
  2. bool flagSC = true;
  3.  
  4. for(int i=0l i< url.length;i++)
  5. {
  6. if (flagSC == true)
  7. {
  8. webbrowser1.navigate(arrURL[i].ToString());
  9.  
  10. while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
  11. {
  12. Application.DoEvents();
  13. }
  14. }
  15. else
  16. {
  17. i -= 1;
  18. }
  19.  
  20.  
  21. private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  22. flagSC = false;
  23. Bitmap bitmap = new Bitmap(webBrowser1.Bounds.Width, webBrowser1.Bounds.Height);
  24. webBrowser1.DrawToBitmap(bitmap, webBrowser1.Bounds);
  25. bitmap = (Bitmap)bitmap.GetThumbnailImage(175, 128, null, IntPtr.Zero);
  26. bitmap.Save(filePath);
  27. flagSC = true;
  28. bitmap.Dispose(); 
  29. }
  30. }
  31.  
  32.  
The above code gives blank images.

Thanks in advance.
Jun 5 '08 #1
1 1514
Plater
7,872 Recognized Expert Expert
I see in your for loop that you do a i++ but then at the end of the loop you take that one away again.
Any reason for this?

Edit: I just tried the DrawToBitmap method and it worked fine
More Edit: Seems after making one picture, the next one always draw empty...
And More Edit: Well my problem seemed to be that extra call were being made internally to things like "about:blank" and the. I solved it with something like this:
Expand|Select|Wrap|Line Numbers
  1. private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  2.         {
  3.             if (e.Url.ToString() == correctURL)
  4.             {
  5.                 Bitmap bitmap = new Bitmap(webBrowser1.Bounds.Width, webBrowser1.Bounds.Height);
  6.                 webBrowser1.DrawToBitmap(bitmap, webBrowser1.Bounds);
  7.                 bitmap = (Bitmap)bitmap.GetThumbnailImage(175, 128, null, IntPtr.Zero);
  8.                 bitmap.Save(filePath);
  9.                 bitmap.Dispose();
  10.             }
  11.         }
  12.  
Just remember to set correctURL to the URL you are trying to capture the picture of.
Jun 9 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2975
by: mee-shell | last post by:
Hi, I am a python newbie. I have created a tool for capturing the screen shot. I want to be able to do the screen capture with the keydown event as well. The tool worked fine when it first...
2
1632
by: Brent | last post by:
Hello all.. I have a recordset that has 12 records in it, and about 25 columns. Unfortunately, I have to write the records out as columns in an ASP page, and the columns as rows. So, what I have done...
3
6720
by: Mike Anderson | last post by:
I'm having a problem with the positioning of a div block in IE6. http://www.uah.edu/Athletics/index.shtml When the window is resized to a width smaller than the width of the "body" div (that...
4
1621
by: James Park | last post by:
I'm trying to use: keybd_event(VK_SNAPSHOT, 0, 0, 0); keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0); to take a screenshot, and use: Clipboard::GetImage(); to retrieve it, but it...
1
1306
by: Li-fan Chen | last post by:
Hi, In creating an email client, we are trying to allow users to pick and choose their email templates and photo stocks. We thought it'd be very 2006 to show a gallery of thumbnails. Is this a...
1
1736
by: kkrizl | last post by:
I've tried to research this problem, and I haven't been able to find any references to it. Probably because I shouldn't be doing it, but it was working, and now it's not. I'm trying to develop a...
17
2321
by: Navaidstech | last post by:
Hi all... I'm new to Java programming. I've seen how finicky java is as far case and space sensitivity sensitivity is concerned. However, I'm slowly getting hang of it. I came accross this...
5
2433
by: smittie31 | last post by:
I am having a problem with a border around me html page. The border does not flow thru the whole html page, it cuts off halfway. --> See http://keithborom.com/marlon-sanders CSS STYLESHEET ...
13
7895
by: limelites | last post by:
In IE7, FF, Chrome and Safari, everything looks great but in Opera the display of the additional images in my product page looks awful. This is a site that does attract foreign visitors who do use...
0
7051
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
7054
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6750
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4493
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3003
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.