save Silverlight 5 web application screen shot to disk

Asked by
I want to take a screen shot from my web-based Silverlight 5 application and save it on disk, what are my options? I've searched a lot but found nothing useful.

Best Answer

Answer by
http://www.silverlightshow.net/items/Capturing-a-Silverlight-Screen.aspx appears to capture and save it to disk

Capture

 // 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();
Save

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

 }

 }

Your Answer

Name:
Answer: