임이 코드를 사용 :WebBrowser 페이지 URL 콘텐츠를 1 초마다 이미지로 저장할 수 있습니까?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Drawing.Imaging;
namespace DownloadFlashFiles
{
public partial class Form1 : Form
{
int i = 0;
public Form1()
{
InitializeComponent();
GenerateScreenshot("http://www.nana10.co.il");
}
private void Form1_Load(object sender, EventArgs e)
{
}
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();
webBrowser1.ScrollBarsEnabled = false;
webBrowser1.ScriptErrorsSuppressed = true;
webBrowser1.Navigate(url);
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
// Set the size of the WebBrowser control
webBrowser1.Width = width;
webBrowser1.Height = height;
if (width == -1)
{
// Take Screenshot of the web pages full width
webBrowser1.Width = webBrowser1.Document.Body.ScrollRectangle.Width;
}
if (height == -1)
{
// Take Screenshot of the web pages full height
webBrowser1.Height = webBrowser1.Document.Body.ScrollRectangle.Height;
}
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
Bitmap bitmap = new Bitmap(webBrowser1.Width, webBrowser1.Height);
webBrowser1.DrawToBitmap(bitmap, new Rectangle(0, 0, webBrowser1.Width, webBrowser1.Height));
//webBrowser1.Dispose();
return bitmap;
}
private void timer1_Tick(object sender, EventArgs e)
{
i++;
Bitmap thumbnail = GenerateScreenshot("http://www.nana10.co.il");
thumbnail.Save(@"d:\test4\" + i.ToString("D6") + "bmp", ImageFormat.Bmp);
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
}
}
}
버튼을 클릭 메신저 나는 그것이 동안 붙어 있기 때문에 WerBrowser의 내용은 매초마다로드하지만이 타이머 1 틱 이벤트 내부 코드에 도착 결코 볼 때 문제는 이 라인에서 루프 :
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
내가 원하는 새 콘텐츠가 웹 브라우저마다 두 번째 오티 또한 매 초마다 하드 디스크에 웹 브라우저에서 새 내용을 저장로드하는 것입니다.
어떻게하면 While 루프에 머물러 있니? 당신을 도움이된다면