Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Map > saving radmap as an image

Not answered saving radmap as an image

Feed from this thread
  • Donna avatar

    Posted on Jun 9, 2011 (permalink)

    Is it possible to somehow save a radmap with an empty provider as an image?  I understand the following:

    "The export to an image in Silverlight is performed using the WriteableBitmap class. We use the MS MultiScaleImage as a base of RadMap control. It does not allow creating the WriteableBitmap with access to its pixels.
    At present, it is not possible to get a screenshot of RadMap to an image."

    and that the reason for this is:

    "Unfortunately, it is impossible, because the map contains images from a site of the map provider (like to Bing or Open Street). The domain name resolver (that's used by WriteableBitmap) requires that the website domain and the MediaElement to be the same to allow pixel access.  So, there is no way to create screenshot of RadMap control programmatically in Silverlight."


    But, if we are not using a map provider from a site, and are instead only using an empty provider, is it possible to create an image from the map?  If so, how would this be done?

    Reply

  • Andrey Andrey admin's avatar

    Posted on Jun 10, 2011 (permalink)

    Hello Donna,

    You can save the contents of the information layer to an image file using ExportExtensions.ExportToImage method.

    The sample code is below.
    private void SaveToImage()
    {
        SaveFileDialog dialog = new SaveFileDialog();
        dialog.Filter = "Png (*.png)|*.png";

        
    bool? dialogResult = dialog.ShowDialog();

        
    if (dialogResult == true)
        {
            using (Stream stream = dialog.OpenFile())
            {
                Telerik.Windows.Media.Imaging.ExportExtensions.ExportToImage(
                    this.informationLayer, stream, new Telerik.Windows.Media.Imaging.PngBitmapEncoder());
            }
        }
    }

    Best wishes,
    Andrey Murzov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Donna avatar

    Posted on Jun 23, 2011 (permalink)

    This works great, however, I can only save one information layer at a time with this code, and I am using multiple information layers at once, one for the us states, one for the canadian provinces, and one for the rest of the world countries.  Is there a way to specify for it to save more than one information layer at a time in the image?

    Reply

  • Andrey Andrey admin's avatar

    Posted on Jun 28, 2011 (permalink)

    Hello Donna,

    The RadMap is an items control. It contains information layers in its items presenter. You can use the FindChildByType extension to get the items presenter and to render it to an image.
    The sample code is below.
    using Telerik.Windows.Controls;
     
    private void SaveToImage()
    {
        SaveFileDialog dialog = new SaveFileDialog();
        dialog.Filter = "Png (*.png)|*.png";
        bool? dialogResult = dialog.ShowDialog();
     
        if (dialogResult == true)
        {
            using (Stream stream = dialog.OpenFile())
            {
                FrameworkElement element = this.radMap.FindChildByType<ItemsPresenter>();
     
                Telerik.Windows.Media.Imaging.ExportExtensions.ExportToImage(
                    element, stream, new Telerik.Windows.Media.Imaging.PngBitmapEncoder());
            }
        }
    }

    All the best,
    Andrey Murzov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Donna avatar

    Posted on Jun 28, 2011 (permalink)

    This works perfectly.  Thank you very much.

    Reply

  • Liam avatar

    Posted on Sep 1, 2011 (permalink)

    Should this approach work when the provider is getting tiles from the source web application? And if so how would I achieve this.

    In trying I still get an access error when trying to capture the map, even when settings an empty map provider
    Using just the ItemsPresenter I can capture the Icons

    background - the map has 3 information layers that display icons on the page. the icon images are also from the web application.
    all referenced URL's are based on the actual URL of the page (hard coding to the development URL also didn't work)

    Reply

  • Andrey Andrey admin's avatar

    Posted on Sep 7, 2011 (permalink)

    Hi Liam,

    Unfortunately it is not possible to save image of the RadMap control with tiles (or even with EmptyProvider), because a bug in the Silverlight MultiScaleImage control. MultiScaleImage control with a custom MultiScaleTileSource cannot be rendered with WriteableBitmap. MS know about this bug and it is marked as fixed in the future version of the Silverlight:

    https://connect.microsoft.com/VisualStudio/feedback/details/628962

    Hopefully it will work in Silverlight 5.

    Best wishes,
    Andrey Murzov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

    Reply

  • Ben avatar

    Posted on Jan 30, 2012 (permalink)

    Does this work in silverlight 5?

    Reply

  • Andrey Andrey admin's avatar

    Posted on Feb 2, 2012 (permalink)

    Hi Ben,

    Yes, it works in the Silverlight 5. Of course the export will work only when you use map tiles from the web-server where the Silverlight application is installed.

    Greetings,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Map > saving radmap as an image