private Bitmap getSymbol(Symbol2D symbol2D) { if (symbol2D == null) { return(null); } SymbolLookupKey key = new SymbolLookupKey(symbol2D.GetHashCode()); Bitmap symbol; _symbolCache.TryGetValue(key, out symbol); if (symbol == null) { MemoryStream data = new MemoryStream(); symbol2D.SymbolData.Position = 0; using (BinaryReader reader = new BinaryReader(new NondisposingStream(symbol2D.SymbolData))) { data.Write(reader.ReadBytes((Int32)symbol2D.SymbolData.Length), 0, (Int32)symbol2D.SymbolData.Length); } symbol = new Bitmap(data); _symbolCache[key] = symbol; } return(symbol); }
private Bitmap getSymbol(Symbol2D symbol2D) { if (symbol2D == null) { return null; } SymbolLookupKey key = new SymbolLookupKey(symbol2D.GetHashCode()); Bitmap symbol; _symbolCache.TryGetValue(key, out symbol); if (symbol == null) { lock (symbol2D) { MemoryStream data = new MemoryStream(); symbol2D.SymbolData.Position = 0; using (BinaryReader reader = new BinaryReader(new NondisposingStream(symbol2D.SymbolData))) { data.Write(reader.ReadBytes((Int32) symbol2D.SymbolData.Length), 0, (Int32) symbol2D.SymbolData.Length); } symbol = new Bitmap(data); if (symbol.PixelFormat != PixelFormat.Undefined) { _symbolCache[key] = symbol; } else { symbol = null; } } } return symbol ?? getSymbol(symbol2D); }