我想在Silverlight 3应用程序内部进行屏幕截图,并将其作为缩略图呈现给用户,比如在一个图像控件中。请问这是否可行?
对于一个简单的页面:
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<Ellipse Fill="Red" Width="100" Height="100"></Ellipse>
<Button x:Name="btnCapture" Click="btnCapture_Click" Width="30" Height="25"></Button>
<Image x:Name="imgThumbnail" Width="50" Height="50"></Image>
</StackPanel>
</Grid>
使用事件处理程序:
private void btnCapture_Click(object sender, RoutedEventArgs e)
{
WriteableBitmap bmp = new WriteableBitmap(LayoutRoot, null);
this.imgThumbnail.Source = bmp;
}
如果你想要进行真正的屏幕截图(插件外部),那么你是在做梦。
如果你只想捕获 Silverlight 应用程序的部分或完整的可视树渲染,那么 WriteableBitmap 的答案是正确的。