[转载]WPF中实现对Flash的播放及(循环)截图
- C#
- 2011-03-05
- 87热度
- 0评论
[转载]WPF中实现对Flash的播放及(循环)截图 - SongShu - 博客园.
要想实现Flash的播放支持,需要借助Flash自身的ActiveX控件.
<Window x:Class="Capture.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:host="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Title="File Capture" Height="600" Width="800"
Unloaded="Window_Unloaded"
>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="150"></ColumnDefinition>
</Grid.ColumnDefinitions>
<host:WindowsFormsHost x:Name="host">
<forms:WebBrowser x:Name="browser"></forms:WebBrowser>
</host:WindowsFormsHost>
<Grid Background="Gray" Grid.Column="1">
<UniformGrid Rows="5" VerticalAlignment="Top">
<Button x:Name="btnOpen" Width="100" Height="30" Click="btnOpen_Click" Margin="0,10">Open File</Button>
<Button x:Name="btnCapture" Width="100" Height="30" Click="btnCapture_Click" Margin="0,10">Start Capture</Button>
<Button x:Name="btnStop" Width="100" Height="30" Click="btnStop_Click" Margin="0,10">Stop Capture</Button>
<CheckBox x:Name="cboxLoop" IsChecked="True" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="25,10,0,10">Loop Capture</CheckBox>
</UniformGrid>
</Grid>
</Grid>
</Window>
[/xml]
browser.Navigate(currentPath);
[csharp]
private void Capture()
{
string fileName = System.IO.Path.GetFileNameWithoutExtension(currentPath);
string capturePath = string.Format("{0}\\Capture\\{1}", System.Environment.CurrentDirectory, fileName);
if (!Directory.Exists(capturePath))
{
Directory.CreateDirectory(capturePath);
}
Bitmap myBitmap = new Bitmap((int)host.ActualWidth, (int)host.ActualHeight);
System.Drawing.Rectangle DrawRect = new System.Drawing.Rectangle(0, 0, (int)host.ActualWidth, (int)host.ActualHeight);
browser.DrawToBitmap(myBitmap, DrawRect);
string timeNow = DateTime.Now.ToString("yyyyMMddHHmmssfff");
myBitmap.Save(string.Format("{0}\\{1}_{2}.png", capturePath, fileName, timeNow));
}
[/csharp]

1 xmlns:host="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" 2 xmlns:forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"