Skip to main content

IImageTileSource.GetImage(Int32, Int32, Int32, Size) Method

Returns an image by the specified indices at a given map control zoom level.

Namespace: DevExpress.XtraMap

Assembly: DevExpress.XtraMap.v22.1.dll

NuGet Package: DevExpress.Win.Map

Declaration

Image GetImage(
    int x,
    int y,
    int level,
    Size size
)

Parameters

Name Type Description
x Int32

The tile x-index.

y Int32

The tile y-index.

level Int32

The map control’s zoom level.

size Size

The tile size.

Returns

Type Description
Image

An image that represents a map tile.

Example

This example shows how to use an ImageTileDataProvider instance to generate map tiles.

View Example

using DevExpress.XtraMap;
using System;
using System.Drawing;
using System.Windows.Forms;

namespace InMemoryTileProvider {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e) {
            ImageTileDataProvider tileDataProvider = new ImageTileDataProvider();
            tileDataProvider.TileSource = new SimpleTileGenerator();
            this.imageLayer1.DataProvider = tileDataProvider;
        }
        public class SimpleTileGenerator : IImageTileSource {
            readonly Font font = new Font("Arial", 10);
            Random rnd = new Random();
            public bool CanDisposeSourceImage => true;
            public string Name => nameof(SimpleTileGenerator);
            public Image GetImage(int x, int y, int level, Size size) {
                Bitmap bitmap = new Bitmap(size.Width, size.Height);
                using (Graphics gr = Graphics.FromImage(bitmap)) {
                    gr.Clear(Color.FromArgb(128, rnd.Next(255),
                            rnd.Next(255), rnd.Next(255)));
                    gr.DrawString(string.Format("{0} {1} {2}", x, y, level),
                           font, Brushes.Black, new PointF(5, 5));
                }
                return bitmap;
            }
        }
    }
}
See Also