MediaElement save Image (Frame) to file
I'm showing video stream in MediaElement (the stream is not from server machine), when the user clicks button开发者_开发百科 I want to show captured frame in Image control, and then user can save this image to file).
My code looks like this:
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);
}
}
The probem is that I get exception:
WriteableBitmap has protected content. Pixel access is not allowed.
Take a look to WriteableBitmap with MediaElement thread on forums.silverlight.net.
From that post
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.
精彩评论