New to Telerik UI for WinForms? Download free 30-day trial

Exporting RadMap to an Image


Product Version 2018.1 220
Product RadMap for WinForms


An article demonstrating how the currently visible part of map control can be exported to an image. The suggested approach will also handle a case painting the layers, making it possible for any pins to be exported as well.


RadMap will be exported with the help of the Graphics and RadGdiGraphics classes.

Figure 1: Exporting RadMap

Control Exported Image
radmap-export-image 001 radmap-export-image 002

The control will be set up with the OpenStreetMapProvider including a layer with pins.

Initial Setup

public RadMapExportImageForm()
    MapLayer pinLayer = new MapLayer("PinsLayer");
    OpenStreetMapProvider osmProvider = new OpenStreetMapProvider();
    osmProvider.InitializationComplete += OsmProvider_InitializationComplete;
private void OsmProvider_InitializationComplete(object sender, EventArgs e)
    MapPin element = new MapPin(new PointG(34.0140562, -118.2880489));
    element.Text = "Los Angeles";
    element.BackColor = Color.Red;
    this.radMap1.BringIntoView(element.Location, 10);

Sub New()
    Dim pinLayer As MapLayer = New MapLayer("PinsLayer")
    Dim osmProvider As OpenStreetMapProvider = New OpenStreetMapProvider()
    AddHandler osmProvider.InitializationComplete, AddressOf OsmProvider_InitializationComplete
End Sub
Private Sub OsmProvider_InitializationComplete(sender As Object, e As EventArgs)
    Dim element As MapPin = New MapPin(New PointG(34.0140562, -118.2880489))
    element.Text = "Los Angeles"
    element.BackColor = Color.Red
    Me.RadMap1.BringIntoView(element.Location, 10)
End Sub

Actual Export Implementation

private void radButton1_Click(object sender, EventArgs e)
    Bitmap bitmap = new Bitmap((int)this.radMap1.MapElement.ViewportInPixels.Size.Width, (int)this.radMap1.MapElement.ViewportInPixels.Height);
    Graphics g = Graphics.FromImage(bitmap);
    RadGdiGraphics gg = new RadGdiGraphics(g);
    foreach (MapVisualElement element in this.radMap1.MapElement.Providers[0].GetContent(this.radMap1.MapElement))
        element.Paint(gg, this.radMap1.MapElement);
    object state = gg.SaveState();
    //As of R2 2021 calling TranslateTransform is not necessary
    //gg.TranslateTransform(-this.radMap1.MapElement.ViewportInPixels.X, -this.radMap1.MapElement.ViewportInPixels.Y);
    this.radMap1.MapElement.Layers["PinsLayer"].Paint(gg, this.radMap1.MapElement);
    bitmap.Save(@"..\..\test.png", ImageFormat.Png);

Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
    Dim bitmap As Bitmap = New Bitmap(CInt(Me.RadMap1.MapElement.ViewportInPixels.Size.Width), CInt(Me.RadMap1.MapElement.ViewportInPixels.Height))
    Dim g As Graphics = Graphics.FromImage(bitmap)
    Dim gg As RadGdiGraphics = New RadGdiGraphics(g)
    For Each element As MapVisualElement In Me.RadMap1.MapElement.Providers(0).GetContent(Me.RadMap1.MapElement)
        element.Paint(gg, Me.RadMap1.MapElement)
    Dim state As Object = gg.SaveState()
    'As of R2 2021 calling TranslateTransform is not necessary
    'gg.TranslateTransform(-Me.RadMap1.MapElement.ViewportInPixels.X, -Me.RadMap1.MapElement.ViewportInPixels.Y)
    Me.RadMap1.MapElement.Layers("PinsLayer").Paint(gg, Me.RadMap1.MapElement)
    bitmap.Save("..\..\test.png", ImageFormat.Png)
End Sub

As of R2 2021 calling the TranslateTransform method for the RadGdiGraphics object is not necessary. For older versions, please make sure that the method is executed.

A complete solution providing a C# and VB.NET project is available here.

In this article
Not finding the help you need? Improve this article