MediaElement将图像(帧)保存到文件

时间:2011-06-21 09:34:48

标签: c# silverlight

我在MediaElement中显示视频流(流不是来自服务器机器),当用户单击按钮我想在Image控件中显示捕获的帧时,然后用户可以将此图像保存到文件中。

我的代码如下所示:

private void TakePicture(object sender, RoutedEventArgs e)
{
    WriteableBitmap writeableBitmap = new WriteableBitmap(uiMediaElement, null);
    uiImage.Source = writeableBitmap;
}

private void SaveImage(object sender, RoutedEventArgs e)
{
    SaveFileDialog saveFileDialog = new SaveFileDialog();
    if (saveFileDialog.ShowDialog() == true)
    {
        Stream stream = saveFileDialog.OpenFile();
        var extendedImage = uiImage.ToImage(); //this is extension method from ImageTools library uiElement.ToImage()
        extendedImage.WriteToStream(stream);
    }
}

探测是我得到例外:

WriteableBitmap具有受保护的内容。不允许像素访问。

1 个答案:

答案 0 :(得分:1)

查看WriteableBitmap with MediaElement上的forums.silverlight.net帖子 从那篇文章

So, the video Uri must match exactly the address bar in order to work even though 
the Silverlight application works fine from all the above address since they point 
to exactly the same asp page.