Problem in taking screenshot of webpages

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpfreak2007
    New Member
    • Sep 2007
    • 31

    #1

    Problem in taking screenshot of webpages

    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.

    Code:
     arrayList arrURL; 
    bool flagSC = true;
     
    for(int i=0l i< url.length;i++)
    {
    if (flagSC == true)
    {
    webbrowser1.navigate(arrURL[i].ToString());
     
    while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
    {
    Application.DoEvents();
    }
    }
    else
    {
    i -= 1;
    }
     
     
    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    { 
    flagSC = false;
    Bitmap bitmap = new Bitmap(webBrowser1.Bounds.Width, webBrowser1.Bounds.Height);
    webBrowser1.DrawToBitmap(bitmap, webBrowser1.Bounds);
    bitmap = (Bitmap)bitmap.GetThumbnailImage(175, 128, null, IntPtr.Zero);
    bitmap.Save(filePath);
    flagSC = true;
    bitmap.Dispose(); 
    }
    }
    The above code gives blank images.

    Thanks in advance.
    Last edited by DrBunchman; Jun 5 '08, 10:24 AM. Reason: Added code tags - Please use the # button
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    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:blan k" and the. I solved it with something like this:
    Code:
    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                if (e.Url.ToString() == correctURL)
                {
                    Bitmap bitmap = new Bitmap(webBrowser1.Bounds.Width, webBrowser1.Bounds.Height);
                    webBrowser1.DrawToBitmap(bitmap, webBrowser1.Bounds);
                    bitmap = (Bitmap)bitmap.GetThumbnailImage(175, 128, null, IntPtr.Zero);
                    bitmap.Save(filePath);
                    bitmap.Dispose();
                }
            }
    Just remember to set correctURL to the URL you are trying to capture the picture of.

    Comment

    Working...