This is a migrated thread and some comments may be shown as answers.

saving radmap as an image

14 Answers 212 Views
Map
This is a migrated thread and some comments may be shown as answers.
Donna
Top achievements
Rank 1
Donna asked on 09 Jun 2011, 02:49 PM
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?

14 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 10 Jun 2011, 04:26 PM
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
0
Donna
Top achievements
Rank 1
answered on 23 Jun 2011, 05:07 PM
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?
0
Andrey
Telerik team
answered on 28 Jun 2011, 12:22 PM
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
0
Donna
Top achievements
Rank 1
answered on 28 Jun 2011, 02:19 PM
This works perfectly.  Thank you very much.
0
Mark
Top achievements
Rank 1
answered on 02 Sep 2011, 02:56 AM
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)
0
Andrey
Telerik team
answered on 07 Sep 2011, 01:48 PM
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 >>

0
Ben
Top achievements
Rank 1
answered on 30 Jan 2012, 06:51 PM
Does this work in silverlight 5?
0
Andrey
Telerik team
answered on 02 Feb 2012, 08:35 AM
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 >>

0
Robin
Top achievements
Rank 1
answered on 12 Oct 2012, 11:54 AM
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
0
Andrey
Telerik team
answered on 17 Oct 2012, 06:34 AM
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.

0
Joe
Top achievements
Rank 1
answered on 09 Jan 2013, 11:32 AM
How can i save the image, using a online provider?
0
Andrey
Telerik team
answered on 11 Jan 2013, 02:44 PM
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.

0
Joe
Top achievements
Rank 1
answered on 14 Jan 2013, 05:05 PM
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?
0
Andrey
Telerik team
answered on 15 Jan 2013, 09:12 AM
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.

Tags
Map
Asked by
Donna
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Donna
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Ben
Top achievements
Rank 1
Robin
Top achievements
Rank 1
Joe
Top achievements
Rank 1
Share this question
or