"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
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
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
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)
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,
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 >>
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 >>
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
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.
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,
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
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?
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.