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

百般思念 提交于 2019-12-06 03:58:01

问题


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,


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/2951371/take-screenshot-of-current-user-control-or-any-gui-in-silverlight-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!