private void GetFullMapThread(CancellationToken ct) { var leftBound = new GeomCoordinate(Properties.Settings.Default.LeftMapBound, Properties.Settings.Default.TopMapBound); var rightBound = new GeomCoordinate(Properties.Settings.Default.RightMapBound, Properties.Settings.Default.BottomMapBound); var rectBound = new CoordinateRectangle(leftBound, rightBound); try { var mapWidth = Convert.ToInt32((new ScreenCoordinate(rectBound.RightTop, _mapLevel)).X - (new ScreenCoordinate(rectBound.LeftTop, _mapLevel)).X) + 2 * TileBlock.BlockSize; var mapHeight = Convert.ToInt32((new ScreenCoordinate(rectBound.LeftBottom, _mapLevel)).Y - (new ScreenCoordinate(rectBound.LeftTop, _mapLevel)).Y) + 2 * TileBlock.BlockSize; var image = GraphicLayer.CreateCompatibleBitmap(null, mapWidth, mapHeight, _mapPiFormat); var graphics = Graphics.FromImage(image); var viewBound = rectBound.LineMiddlePoint.GetScreenViewFromCenter(mapWidth, mapHeight, _mapLevel); var blockView = viewBound.BlockView; var mapBlockCount = (blockView.Right - blockView.Left + 1) * (blockView.Bottom - blockView.Top + 1); var mapBlockNumber = 0; BeginInvoke(ProgressEvent, new Object[] { mapBlockNumber * 100 / mapBlockCount, mapBlockNumber, mapBlockCount }); for (var x = blockView.Left; x <= blockView.Right; x++) { for (var y = blockView.Top; y <= blockView.Bottom; y++) { var block = new TileBlock(x, y, _mapLevel); var bmp = GraphicLayer.CreateCompatibleBitmap( TileLayer.DownloadImageFromFile(block) ?? TileLayer.DownloadImageFromTile(block, true), TileBlock.BlockSize, TileBlock.BlockSize, _mapPiFormat); var rect = ((ScreenRectangle)block).GetScreenRect(viewBound); graphics.DrawImageUnscaled(bmp, rect.Location.X, rect.Location.Y); mapBlockNumber++; BeginInvoke(ProgressEvent, new Object[] { mapBlockNumber * 100 / mapBlockCount, mapBlockNumber, mapBlockCount }); if (ct.IsCancellationRequested) { return; } } } BeginInvoke(SaveMapEvent, new Object[] { image }); } catch (Exception e) { BeginInvoke(ProgressEvent, new Object[] { 101, 0, 0 }); MessageBox.Show(e.Message, @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }