2013-03-29 100 views
0

我想從我的基於Web的Silverlight 5應用程序中截取屏幕截圖並將其保存在磁盤上,我的選擇是什麼?我搜索了很多,但沒有發現有用的東西。保存Silverlight 5 web應用程序屏幕截圖到磁盤

+0

我假設你想以編程方式做到這一點? –

+0

是的,我在我的XAMl中有一些控件,然後當用戶點擊一個按鈕時我想捕捉一個捕捉,那麼用戶應該能夠下載捕捉的圖像 –

回答

1

This似乎捕捉並保存到磁盤

捕捉

// create a WriteableBitmap 

WriteableBitmap bitmap = new WriteableBitmap(

    (int)this.LayoutRoot.ActualWidth, 

    (int)this.LayoutRoot.ActualHeight); 



// render the visual element to the WriteableBitmap 

bitmap.Render(this.LayoutRoot, this.transform); 



// request an redraw of the bitmap 

bitmap.Invalidate(); 

保存

private void ThumbnailClicked(object sender, MouseButtonEventArgs e) 

{ 

    // pause the capture timer 

    this.timer.Stop(); 

    try 

    { 

     // locate the WriteableBitmap source for the clicked image 

     WriteableBitmap bitmap = ((Image)sender).Source as WriteableBitmap; 

     if (null == bitmap) 

     { 

      MessageBox.Show("Nothing to save"); 

      return; 

     } 



     // prompt for a location to save it 

     if (this.dialog.ShowDialog() == true) 

     { 

      // the "using" block ensures the stream is cleaned up when we are finished 

      using (Stream stream = this.dialog.OpenFile()) 

      { 

       // encode the stream 

       JPGUtil.EncodeJpg(bitmap, stream); 

      } 

     } 

    } 

    finally 

    { 

     // restart the capture timer 

     this.timer.Start(); 

    } 

} 
+0

什麼是this.transform?我沒有,我可以使用單位轉換控制嗎?用戶可以從網上下載保存的圖像嗎? –

+0

我建議閱讀這篇文章,而不僅僅是代碼「你可以通過一個轉換到渲染方法來縮放,旋轉,傾斜和/或翻譯被渲染的元素。」 –

+1

什麼是JpgUtil? –