saving radmap as an image

15 posts, 0 answers
  1. Donna
    Donna avatar
    12 posts
    Member since:
    Dec 2010

    Posted 09 Jun 2011 Link to this post

    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?

  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 10 Jun 2011 Link to this post

    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
  3. DevCraft banner
  4. Donna
    Donna avatar
    12 posts
    Member since:
    Dec 2010

    Posted 23 Jun 2011 Link to this post

    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?
  5. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 28 Jun 2011 Link to this post

    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
  6. Donna
    Donna avatar
    12 posts
    Member since:
    Dec 2010

    Posted 28 Jun 2011 Link to this post

    This works perfectly.  Thank you very much.
  7. Mark
    Mark avatar
    29 posts
    Member since:
    Aug 2010

    Posted 01 Sep 2011 Link to this post

    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)
  8. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 07 Sep 2011 Link to this post

    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 >>

  9. Ben
    Ben avatar
    3 posts
    Member since:
    Oct 2011

    Posted 30 Jan 2012 Link to this post

    Does this work in silverlight 5?
  10. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 02 Feb 2012 Link to this post

    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 >>

  11. Robin
    Robin avatar
    19 posts
    Member since:
    Feb 2011

    Posted 12 Oct 2012 Link to this post

    Hi Andrey,

    so is it now possible to save the whole map as PNG?

    I still get the SecurityException when I try to use the ExportToImage function of the ExportExtensions.

    We are using Silverlight 5 and RadControls Version 2012.1.326.1050.
    The tiles are loaded from the same web server.

    Microsoft has marked the isse as closed & fixed:
    https://connect.microsoft.com/VisualStudio/feedback/details/628962
  12. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 17 Oct 2012 Link to this post

    Hello Robin,

    We have checked this functionality and it works as expected. I have attached a sample solution which exports the map as PNG image.

    Kind regards,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  13. Joe
    Joe avatar
    15 posts
    Member since:
    May 2009

    Posted 09 Jan 2013 Link to this post

    How can i save the image, using a online provider?
  14. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 11 Jan 2013 Link to this post

    Hello Joe,

    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 when when you use map tiles from the web-server different from one where the Silverlight application is installed (i.e. it is impossible with Bing, OpenStreet, ArcGIS and similar providers).

    Kind regards,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  15. Joe
    Joe avatar
    15 posts
    Member since:
    May 2009

    Posted 14 Jan 2013 Link to this post

    Actually, i managed to get the image, using the service http://api.tiles.virtualearth.net/api/GetMap.ashx.

    I 've found also the class ImageryServiceClient at the telerik DLLs, the service http://dev.virtualearth.net/webservices/v1/imageryservice/imageryservice.svc
    should help me to get the image trough this class, can not?
  16. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 15 Jan 2013 Link to this post

    Hi Joe,

    It is up to you to use imagery services (Bing Map, for example) directly. However, please note that this is outside of the scope of RadMap support.

    Greetings,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner