Is there a way to get the Silverlight UI Element as an image?

I want to export an image of my ArcGIS map object with a graphic layer on it. I tried to use my own esri web services for export, but they are not so efficient and understandable that they don’t support complex geometric shapes and they don’t support local layers like Google map provider. The service only supports ArcGISTiledLayer, I want it at all levels. So, I searched on their forums, but they say that they will not support local levels until the next versions.

I tried ImageTool libraries and WritableBitmapEx libraries in codeplex. But when I try to get byte [] from WritableBitmap, I cannot access the Pixels property for some security reasons all the time. The application throws a SecurityException and says "you cannot access this pixel property."

So, is there a way to get the UIElement control image and save it to disk? Or is there a workaround for this security exception?

+5
source share
1 answer

Yes, the image tool library has a way to do this in png / jpg, etc.

http://imagetools.codeplex.com/

RenderTargetBitmap - http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx

, .

http://www.silverlightshow.net/items/Using-the-SaveFileDialog-in-Silverlight-3.aspx

EDIT -

var objImage = new WritableBitmap(MyElement, MyElement.RenderTransform);

var bytData = objImage.ToPng();

using ImageTools.IO.Png;
using ImageTools;

public static byte[] ToPng(this WriteableBitmap Image)
{
    byte[] bytResult;

    using (MemoryStream objPngStream = new MemoryStream())
    {
        PngEncoder objPngEncoder = new PngEncoder();
        objPngEncoder.Encode(Image.ToImage(), objPngStream);
        objPngStream.Seek(0, SeekOrigin.Begin);
        bytResult = objPngStream.ToArray();
        objPngStream.Close();
    }
    return bytResult;
}
+5

All Articles