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

Export map as an image

1 Answer 256 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Giuseppe asked on 18 Aug 2020, 02:46 PM

Is it possible to export a RadMap to an image or some other type, something I could reference in html content as a report? This would be for a Xamarin Native (iOS and Android) project, but a solution for Xamarin.Forms would work too.

While searching for an answer to my export question, I found this feedback:

Do you only support the WGS84 geographic coordinate system? If I add projected shapefiles, it would not work?

Thank you.

1 Answer, 1 is accepted

Sort by
Lance | Manager Technical Support
Telerik team
answered on 18 Aug 2020, 04:05 PM

Hello Giuseppe,

Xamarin.Forms does not have the capability to export UI elements as an image, thus Telerik UI for Xamarin does not have it either.

Custom DependencyService

However, you can write a custom Xamarin.Forms DependencyService to leverage the native platform's features and render that native screen to a png or jpg using the native platform APIs.

I have an open source demo project that shows you how to do this:

  1. Go to my Custom Xamarin Demos repository.
  2. Go into the Render Image demo's folder.
  3. Read the README very carefully to understand how to use the DependencyService (specifically the Methods section, you can ignore the PDF section).

You may be asking yourself how to pass in a specific UI control, but you'll see that there is no easy way to do that because the native platform doesn't know what a Xamarin.Forms control is.

So, the DependencyService methods has works by rendering the screen, then cropping out the section of the screen you want.  Here's the overload of the method:


The Render method returns a byte[] of a png or jpeg encoded image and has overloads to set a cropping region.

  1. RenderAsync(RenderEncodingOptions encodingFormat): Returns a capture of entire screen.
  2. RenderAsync(int X, int Y, int Width, int Height, RenderEncodingOptions encodingFormat): Returns a capture of a cropped region using absolute position values
  3. RenderRelativeAsync(int X, int Y, int Width, int Height, RenderEncodingOptions encodingFormat): Renders a capture of a cropped region using proportional position values

Options 2 and 3 give you the ability to crop any section of the screen so that you can get capture of specific content (e.g. Charts, Graphs, Scoreboards, etc). All methods have a default encoding of RenderEncodingOptions.Png, but you can choose RenderEncodingOptions.Jpeg when needed (i.e. inserting into a PDF).

Using the Image

    Once you get the png/jpg encoded byte[] back from the DependencyService, you can whatever you want with it (e.g. embed it in an HTML report).

    > Please be aware that the example is not an official Telerik demo and we do not provide support for it. I get the question of exporting frequently enough that I wanted to build a demo to give developers a head start.

    Map Projections

    Regarding the 2nd question on projection, I see you have already found the feature request to support other projections. At this time, the Feature Request is set to Unplanned.

    This means it has been approved as a viable feature, but is not currently planned for a specific release (i.e. it hasn't started development, the team will monitor demand for the Feature Request and adjust its priority accordingly).

    You can convert some projections coordinates with 3rd party libraries and there are dozens of articles and topics on the matter online.

    For example, you could also use a library like ProjNET (highly recommended, the ProjNET4GeoAPI NuGet package port written by a Microsoft MVP). I recently used ProjNET to do a conversion from UTM coordinates, here's what that looks like:

    Further Assistance

    If you have any specific trouble with the RadMap, please open a Support Ticket and share the problematic code. The team will be able to give you specific help for your code, privately.

    We do our best to answer forum threads in a timely fashion, but it can take up to several days depending on current support load (i.e. 24hr Support Tickets always take priority over forum posts).

    Lance | Manager - Technical Support
    Progress Telerik

    Asked by
    Top achievements
    Rank 1
    Answers by
    Lance | Manager Technical Support
    Telerik team
    Share this question