2012-05-30 96 views
1

我有一个奇怪的问题,我采取单词的列表,并通过做谷歌搜索字创建屏幕截图.. 它创建像50个屏幕截图后,它开始创建空白图像!创建缩略图失败,并创建空白图像

有人可以帮我解决这个问题!

PS:让我知道,如果我需要更清晰!

这是我用来创建屏幕截图的代码...在我的主页上,我只是循环上我的话!

有人可以帮我解决这个问题

public class GeneateScreenshot 
{ 
public void GenerateScreenshot() 
    { 

    } 
public Bitmap GenerateScreenshot(string url) 
{ 
    // This method gets a screenshot of the webpage 
    // rendered at its full size (height and width) 

    return GenerateScreenshot(url, -1, -1); 
} 

public Bitmap GenerateScreenshot(string url, int width, int height) 
{ 
    // Load the webpage into a WebBrowser control 

    WebBrowser wb = new WebBrowser(); 
    wb.ScrollBarsEnabled = false; 
    wb.ScriptErrorsSuppressed = true; 
    wb.Navigate(url); 
    while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } 


    // Set the size of the WebBrowser control 
    wb.Width = width; 
    wb.Height = height; 

    if (width == -1) 
    { 
     // Take Screenshot of the web pages full width 
     wb.Width = wb.Document.Body.ScrollRectangle.Width; 
    } 

    if (height == -1) 
    { 
     // Take Screenshot of the web pages full height 
     wb.Height = wb.Document.Body.ScrollRectangle.Height; 
    } 

    // Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control 
    Bitmap bitmap = new Bitmap(wb.Width, wb.Height); 
    wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height)); 
    wb.Dispose(); 

    return bitmap; 
} 

}

+1

有多快被这个循环通过? Google不喜欢自动查询,如果您自己收到空白网页,我不会感到惊讶。我建议可能每隔几次加载就会保存网页浏览器控件的结果HTML,并查看HTML是否在某个时刻剧烈变化。 – MindingData

+0

像7-8分钟100个问题! – helpme

回答

1

我怀疑DrawToBitmap功能不是一个WebBrowser控件转换为图像的正确途径。看看下面的链接,看起来你需要使用一些本地方法可靠地做到这一点:

WebBrowser.DrawToBitmap() or other methods?

Converting WebBrowser.Document To A Bitmap?

http://www.codeproject.com/Articles/58605/HTML-to-Image-in-C

附:当玩这个代码时,我很快就被Google的机器人探测器拿走了,所以你也可能在那里遇到麻烦。