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;
}

}

4

1 に答える 1

1

このDrawToBitmap関数は、WebBrowserコントロールを画像に変換する正しい方法ではないようです。次のリンクを確認してください。確実に実行するには、いくつかのネイティブメソッドを使用する必要があるようです。

WebBrowser.DrawToBitmap()または他のメソッド?

WebBrowser.Documentをビットマップに変換しますか?

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

PSこのコードで遊んでいると、私はグーグルのロボット検出器にすぐに拾われたので、そこでも問題が発生する可能性があります。

于 2012-05-30T22:52:41.200 に答える