2011-06-21 219 views
0

我在MediaElement中顯示視頻流(該流不是來自服務器機器),當用戶單擊按鈕時我想在Image控件中顯示捕獲的幀,然後用戶可以保存此圖像到文件)。MediaElement將圖像(幀)保存到文件

我的代碼如下所示:

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); 
    } 
} 

的probem是,我得到異常:

WriteableBitmap的已保護的內容。像素訪問是不允許的。

回答

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. 
+0

我讀這個線程,流是無法從服務器的機器。我不能把它放在服務器上。 –

+0

你是從客戶端計算機流式傳輸視頻嗎? –

+0

不,它來自我們的媒體服務器 –