Example #1
0
        public static ElementImage Merge4Tiles(ElementImage[] tiles)
        {
            if (tiles.Length == 0) return null;

            Image im = new Bitmap(tiles[0].Image.Width << 1, tiles[0].Image.Height << 1);
            Graphics g = Graphics.FromImage(im);

            double bott = tiles.Min(t => t.Box.MinLat);
            double left = tiles.Min(t => t.Box.MinLon);
            double h = tiles.Max(t => t.Box.MaxLat) - bott;
            double w = tiles.Max(t => t.Box.MaxLon) - left;

            for (int i = 0; i < tiles.Length; i++)
            {
                Point pt = new Point();

                int x = Convert.ToInt32((tiles[i].Box.MinLon - left) / w * im.Width);
                int y = Convert.ToInt32((tiles[i].Box.MinLat - bott) / h * im.Width);

                pt.X = x;
                pt.Y = im.Height >> 1 - y;

                g.DrawImageUnscaled(tiles[i].Image, pt);
            }

            ElementImage tile = new ElementImage(bott + h, bott, left, left + w, im);
            return tile;
        }