Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Take Screenshot of current user control or any GUI in Silverlight 3

I would like to ask if it is possible to take screenshot of current user control programmatically and save as a file in silverlight 3.

I found some ways to save as an image file for a Canvas in silverlight 3, but how about user control or childwindow ?

Thanks,

like image 856
Devphil Avatar asked Jun 01 '10 16:06

Devphil


2 Answers

Writable Bitmap will let you do it. See the samples and examples.

like image 103
Srikar Doddi Avatar answered Oct 23 '22 18:10

Srikar Doddi


Not sure about silverlight 3, but in 4 it's done like this:

public static byte[] CreatePngImage(this UIElement element)
{
    WriteableBitmap screenshot = new WriteableBitmap(element, new TranslateTransform());
    var image =  screenshot.ToImage();
    ImageTools.IO.Png.PngEncoder png = new ImageTools.IO.Png.PngEncoder();

    using (var mem = new System.IO.MemoryStream())
    {
        png.Encode(image, mem);
        var bytes = mem.GetBuffer();
        return bytes;
    }
}

where ImageTools.IO.Png.dll could be found here

like image 2
ren Avatar answered Oct 23 '22 19:10

ren