0
我想爲視頻的前30秒拍攝ScreenShoot()。但是當我在webBrowser1_DocumentCompleted中調用它時,它會停止加載視頻。所以屏幕截圖將是空白的。這只是我的代碼的粗略副本。是否有一種方法可以在所有內容完全加載並播放視頻後調用takeScreenShoot()方法?或者在newForm.ShowDialog()之後調用它。 ?在webBrowser1_DocumentCompleted中調用我的函數沒有完成加載瀏覽器
main(
Form1 newForm = new Form1();
newForm.loadStream();
newForm.ShowDialog();
}
public void loadVideo()
{
//// When the form loads, open this web page.
//this.webBrowser1.Navigate("http://www.dotnetperls.com/");
SuppressScriptErrorsOnly(webBrowser1);
//set browser eumulator to IE8
var appName = Process.GetCurrentProcess().ProcessName + ".exe";
SetIE8KeyforWebBrowserControl(appName);
webBrowser1.Navigate("http://youtu.be/e-ORhEE9VVg?list=PLFgquLnL59alLAsVmUulfe3X-BrPzoYAH");
webBrowser1.ScriptErrorsSuppressed = true;
//Console.WriteLine("loading new new");
}
public void takeScreenShoot()
{
DateTime startTime = DateTime.Now;
int i = 0;
string location = @"F:\Twitch Screenshoot\testing\";
while (true)
{
//If time is greater than 30 seconds start taking picture
if (DateTime.Now.Subtract(startTime).TotalSeconds > 1)
{
if (DateTime.Now.Subtract(startTime).TotalSeconds > i + 1)
{
Console.WriteLine("Taking Picture\n");
// The size of the browser window when we want to take the screenshot (and the size of the resulting bitmap)
Bitmap bitmap = new Bitmap(1024, 768);
Rectangle bitmapRect = new Rectangle(0, 0, 1024, 768);
// This is a method of the WebBrowser control, and the most important part
this.webBrowser1.DrawToBitmap(bitmap, bitmapRect);
// Generate a thumbnail of the screenshot (optional)
System.Drawing.Image origImage = bitmap;
System.Drawing.Image origThumbnail = new Bitmap(120, 90, origImage.PixelFormat);
Graphics oGraphic = Graphics.FromImage(origThumbnail);
oGraphic.CompositingQuality = CompositingQuality.HighQuality;
oGraphic.SmoothingMode = SmoothingMode.HighQuality;
oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
Rectangle oRectangle = new Rectangle(0, 0, 120, 90);
oGraphic.DrawImage(origImage, oRectangle);
// Save the file in PNG format
origThumbnail.Save(location + "Screenshot" + i + ".png", ImageFormat.Png);
origImage.Dispose();
i++;
}
}
//stop taking picture when time is greater than 3.
if (DateTime.Now.Subtract(startTime).TotalMinutes > 1)
{
//should close form here
this.Close();
break;
}
}
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (e.Url.AbsolutePath != (sender as WebBrowser).Url.AbsolutePath)
{
var webBrowser = sender as WebBrowser;
webBrowser.DocumentCompleted -= webBrowser1_DocumentCompleted;
Console.WriteLine("loading {0} \n");
this.takeScreenShoot();
}
}
我很確定你連接的視頻是Adobe Flash的問題。然而[用Selenium截圖](http://stackoverflow.com/questions/7642519/taking-screenshot-of-flash-object-using-selenium-with-webdriver?lq=1)可能工作。 – Eris
感謝您的信息。我能否將硒與我的表格結合?我可以運行多個硒嗎? –
我對Selenium並不很有經驗。我知道它可以在需要WebBrowser的任何地方使用,並且可以有多個實例。我建議查看http://docs.seleniumhq.org/support/上的資源以獲取更具體的信息。 – Eris