public TileBitmap CreateBitmapByTile(LevelDef level, int beginRow, int beginCol, int width, int height, TileIdentify tile, out bool memoryIsNotEnough) { memoryIsNotEnough = false; try { T[][] buffers = null; bool isOK = ReadRasterFile(out buffers, beginRow, beginCol, width, height, tile); if (!isOK) { return(null); } TileBitmap tb = new TileBitmap(); tb.Level = level; tb.Tile = tile; tb.Bitmap = BuildBitmap(buffers, level, tile); return(tb); } catch (OutOfMemoryException) { memoryIsNotEnough = true; } catch (ArgumentException) { memoryIsNotEnough = true; } return(null); }
//只留当前屏幕显示的几个瓦片,其余全部释放 public void Deactive() { if (!_isActive) { return; } try { TileIdentify[] visibleTiles; LevelDef suitableLevel; _tilesLocator.Compute(_canvas, out suitableLevel, out visibleTiles); if (visibleTiles == null) { return; } foreach (TileIdentify tile in visibleTiles) { TileBitmap tb = _tileCacheManager.Get(suitableLevel.LevelNo, tile.Row, tile.Col); if (tb != null) { _sleepTileCacheManager.Put(tb); _tileCacheManager.Remove(tb); } } } finally { SetToSleep(); _isActive = false; } }
private void DrawByTiles(IDrawArgs drawArgs) { LevelDef nearestLevel; Rectangle rect; int bRow, bCol, rows, cols; TileIdentify[] tiles = _tileBitmapProvider.GetVisibleTiles(out nearestLevel, out rect, out bRow, out bCol, out rows, out cols); if (_isFirst || tiles == null) { _isFirst = false; return; } if (rows == 0 || cols == 0) { return; } if (tiles != null) { //compute envelope DrawEngine.CoordPoint location = new DrawEngine.CoordPoint(_originalEnvelope.MinX + _originalResolutionX * rect.X, _originalEnvelope.MinY + _originalResolutionY * (_dataProvider.Height - (rect.Y + rect.Height))); _envelope = new DrawEngine.CoordEnvelope(location, _originalResolutionX * rect.Width, _originalResolutionY * rect.Height); //build empty bitmap int tileSize = _tileBitmapProvider.TileComputer.TileSize; int powerOf2 = _tileSetting.PowerOf2; int w = cols << powerOf2; //cols * tileSize int h = rows << powerOf2; //rows * tileSize if (_bitmap != null && (_preHeight != h || _preWidth != w)) { _bitmap.Dispose(); _bitmap = null; } if (_bitmap == null) { _bitmap = new Bitmap(w, h, PixelFormat.Format24bppRgb); } _preWidth = w; _preHeight = h; // using (Graphics g = Graphics.FromImage(_bitmap)) { foreach (TileIdentify t in tiles) { TileBitmap tb = _tileBitmapProvider.GetTileBitmap(t); if (tb.IsEmpty()) { continue; } int x = (t.Col - bCol) << powerOf2; //(t.Col - bCol) * tileSize int y = (t.Row - bRow) << powerOf2; //(t.Row - bRow) * tileSize; //tb.Bitmap.Save("f:\\x" + t.Row.ToString() + "_" + t.Col.ToString()+".bmp", ImageFormat.Bmp); g.DrawImage(tb.Bitmap, x, y); } } } }
public void Remove(TileBitmap tileBitmap) { int key = tileBitmap.Tile.TileNo; if (_cachedTiles.ContainsKey(key)) { _cachedTiles.Remove(key); } }
public void Clear() { foreach (int id in _cachedTiles.Keys) { TileBitmap tb = _cachedTiles[id]; tb.Dispose(); } _cachedTiles.Clear(); }
public void Remove(TileBitmap tileBitmap) { string key = GetKey(tileBitmap); if (_cachedTiles.ContainsKey(key)) { _cachedTiles.Remove(key); } }
public void Clear() { while (_cachedTiles.Count > 0) { TileBitmap tb = _cachedTiles[_cachedTiles.Keys.First()]; _cachedTiles.Remove(_cachedTiles.Keys.First()); tb.Dispose(); } _cachedTiles.Clear(); }
public void Put(TileBitmap tileBitmap) { lock (_cachedTiles) { int key = tileBitmap.Tile.TileNo; if (!_cachedTiles.ContainsKey(key) && _currentVisibleTiles.Contains(key)) { _cachedTiles.Add(key, tileBitmap); } } }
public void Put(TileBitmap tileBitmap) { if (_cachedTiles.Count == MAX_CACHE_TILE_COUNT) { _cachedTiles.Remove(_cachedTiles.Keys.First()); } string key = GetKey(tileBitmap); if (!_cachedTiles.ContainsKey(key)) { _cachedTiles.Add(key, tileBitmap); } }
private TileBitmap LoadTileBitmap(TileIdentify tile) { int beginRow = 0, beginCol = 0, width = 0, height = 0; LevelDef level = tile.Level; level.GetOriginalRowColByDataBlock(tile, ref beginRow, ref beginCol, ref width, ref height); TileBitmap tb = _dataProviderReader.CreateBitmapByTile(level, beginRow, beginCol, width, height, tile); if (!_disposed && tb != null) { _tileCacheManager.Put(tb); } return(tb); }
private TileBitmap LoadTileBitmap(TileIdentify tile, out bool memoryIsNotEnough) { memoryIsNotEnough = false; int beginRow = 0, beginCol = 0, width = 0, height = 0; LevelDef level = tile.Level; level.GetOriginalRowColByDataBlock(tile, ref beginRow, ref beginCol, ref width, ref height); TileBitmap tb = _dataProviderReader.CreateBitmapByTile(level, beginRow, beginCol, width, height, tile, out memoryIsNotEnough); if (!_disposed && tb != null) { _tileCacheManager.Put(tb); _loadedTitleCount++; } return(tb); }
public TileBitmap CreateBitmapByTile(LevelDef level, int beginRow, int beginCol, int width, int height, TileIdentify tile) { lock (_lockObj) { T[][] buffers = null; //从磁盘中读取缓存的瓦片 tryAgainLine: if (_enableDiskCache && _fileDiskCacheManager.IsExist(tile, _selectedBandNos)) { buffers = new T[_selectedBandNos.Length][]; for (int i = 0; i < _selectedBandNos.Length; i++) { buffers[i] = _fileDiskCacheManager.GetTile <T>(tile, _selectedBandNos[i]); if (buffers[i] == null)//缓存已经从磁盘清除 { goto tryAgainLine; } } } else { bool isOK = ReadRasterFile(out buffers, beginRow, beginCol, width, height, tile); if (!isOK) { return(null); } Console.WriteLine("direct read , " + Environment.TickCount.ToString()); //将该瓦片保存在磁盘 if (_enableDiskCache) { _asyncCacheHandler.BeginInvoke(buffers, tile, _selectedBandNos, null, null); } } TileBitmap tb = new TileBitmap(); tb.Level = level; tb.Tile = tile; tb.Bitmap = BuildBitmap(buffers, level, tile); return(tb); } }
private string GetKey(TileBitmap tileBitmap) { return(string.Format("L{0}R{1}C{2}", tileBitmap.Level.LevelNo, tileBitmap.Tile.Row, tileBitmap.Tile.Col)); }