Wednesday, January 23, 2013

Take a screenshot with silverlight 5 / xna

Take a screenshot with silverlight 5 / xna

I'm trying to take a screenshot of a subclassed XNA DrawingSurface element from within a silverlight 5 application. This sl app will run inside an aspx page.

Here's what I've tried so far without success:

WriteableBitmap bmp = new WriteableBitmap(LayoutRoot, null);  testImage.Source = bmp;  

with LayoutRoot being the parent control on the silverlight page and testImage is just an Image control on the page to see if the screenshot is correct.

This will render all the silverlight controls on the page just fine, but the drawingsurface part remains empty. In other words the XNA content is not rendered into the image.

I've also tried to render the XNA content to a RenderTarget2D, but the silverlight version of the render target does not seem to have any methods to save the data. I saw some WP7 examples that used a method called SaveAsJpeg(), but that doesn't seem to be available in the SL5 version of the class.

I would appreciate any help with this.

Greets,

Floris

Answers & Comments...

Answer: 1

One possibility would be to draw your screen into a RenderTarget2D and then use the method SaveAsPng like:

using (Stream stream = File.OpenWrite("filename.png")) { renderTarget2D.SaveAsPng(stream, renderTarget2D.Width, renderTarget2D.Height); } 
by : pad_areshttp://stackoverflow.com/users/1955152




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog