Dwarrowdelf.Client.SymbolBitmapCache.GetBitmap C# (CSharp) Method

GetBitmap() public method

public GetBitmap ( SymbolID symbolID, Color color, bool dark ) : System.Windows.Media.Imaging.BitmapSource
symbolID SymbolID
color Color
dark bool
return System.Windows.Media.Imaging.BitmapSource
        public BitmapSource GetBitmap(SymbolID symbolID, Color color, bool dark)
        {
            Dictionary<Color, CacheData> map;
            CacheData data;

            if (color == Colors.Black)
            {
                data = m_blackBitmapList[(int)symbolID];

                if (data == null)
                {
                    data = new CacheData();
                    m_blackBitmapList[(int)symbolID] = data;
                }
            }
            else
            {
                if (!m_bitmapMap.TryGetValue(symbolID, out map))
                {
                    map = new Dictionary<Color, CacheData>();
                    m_bitmapMap[symbolID] = map;
                }

                if (!map.TryGetValue(color, out data))
                {
                    data = new CacheData();
                    map[color] = data;
                }
            }

            if (!dark)
            {
                if (data.Bitmap == null)
                {
                    BitmapSource bmp = CreateSymbolBitmap(symbolID, color, dark);
                    data.Bitmap = bmp;
                }

                return data.Bitmap;
            }
            else
            {
                if (data.BitmapDark == null)
                {
                    BitmapSource bmp = CreateSymbolBitmap(symbolID, color, dark);
                    data.BitmapDark = bmp;
                }

                return data.BitmapDark;
            }
        }

Usage Example

コード例 #1
0
ファイル: MapControl4.cs プロジェクト: tomba/dwarrowdelf
        public MapControl4()
        {
            m_drawingCache = new DrawingCache();
            m_symbolDrawingCache = new SymbolDrawingCache(m_drawingCache);
            m_symbolBitmapCache = new SymbolBitmapCache(m_symbolDrawingCache, m_tileSize);

            m_map = new Map(512, 512);
            for (int y = 0; y < m_map.Height; ++y)
            {
                for (int x = 0; x < m_map.Width; ++x)
                {
                    m_map.MapArray[y, x] = (x + (y % 2)) % 2 == 0 ? (byte)50 : (byte)255;
                }
            }

            m_bmpArray = new BitmapSource[10];
            for (int i = 0; i < 10; ++i)
                m_bmpArray[i] = m_symbolBitmapCache.GetBitmap((SymbolID)i, Colors.Black, false);

            m_mcd2d = new TileControlD2D();
            m_mcd2d.SetSymbolBitmaps(m_bmpArray, m_tileSize);
            AddChild(m_mcd2d);
        }