private void LoadSelectedMapImages() { SelectedMapTiles = new ObservableCollection <MapTile>(); Bitmap createdBitmap; Bitmap sourceBitmap; Bitmap chunkOfBitmap; int blockToLoad; for (int i = 0; i < SelectedMap.MapBlockValues.Count(); i++) { blockToLoad = SelectedMap.MapBlockValues[i]; if (blockToLoad >= BlockSets.ElementAt((int)selectedMap.TileSetID).Tiles.Count()) { blockToLoad = 0; } sourceBitmap = BlockSets.ElementAt((int)selectedMap.TileSetID).Tiles.ElementAt(blockToLoad); createdBitmap = new Bitmap(32, 32); using (Graphics g = Graphics.FromImage(createdBitmap)) { g.DrawImage(sourceBitmap, 0, 0); foreach (var ob in selectedMap.MapObjects) { if (i == MatchesBlock(ob.XPosition, ob.YPosition, selectedMap.Width)) { chunkOfBitmap = Sprites.ElementAt(ob.SpriteID).SpriteBitmap.Clone(new Rectangle(0, 0, 16, 16), Sprites.ElementAt(ob.SpriteID).SpriteBitmap.PixelFormat); int xpos = (ob.XPosition % 2) * 16; int ypos = (ob.YPosition % 2) * 16; g.DrawImage(chunkOfBitmap, xpos, ypos, 16, 16); if (selectedMapObject != null) //highlite the selected object. { if (selectedMapObject.XPosition == ob.XPosition && selectedMapObject.YPosition == ob.YPosition) { g.DrawRectangle(new Pen(Color.Red, 2), new Rectangle(xpos, ypos, 16, 16)); } } } } foreach (var warp in selectedMap.WarpsLeaving) { if (i == MatchesBlock(warp.XPosition, warp.YPosition, selectedMap.Width)) { int xpos = (warp.XPosition % 2) * 16; int ypos = (warp.YPosition % 2) * 16; if (selectedMapWarp != null) //highlite the selected warp. { if (selectedMapWarp.XPosition == warp.XPosition && selectedMapWarp.YPosition == warp.YPosition) { g.DrawRectangle(new Pen(Color.Purple, 2), new Rectangle(xpos + 2, ypos + 2, 12, 12)); } else { g.DrawRectangle(new Pen(Color.Blue, 2), new Rectangle(xpos + 2, ypos + 2, 12, 12)); } } else { g.DrawRectangle(new Pen(Color.Blue, 2), new Rectangle(xpos + 2, ypos + 2, 12, 12)); } } } foreach (var warp in selectedMap.WarpsArriving) { if (i == MatchesBlock(warp.XPosition, warp.YPosition, selectedMap.Width)) { int xpos = (warp.XPosition % 2) * 16; int ypos = (warp.YPosition % 2) * 16; if (selectedMapWarpArrive != null) //highlite the selected warp. { if (selectedMapWarpArrive.XPosition == warp.XPosition && selectedMapWarpArrive.YPosition == warp.YPosition) { g.DrawRectangle(new Pen(Color.Green, 2), new Rectangle(xpos, ypos, 16, 16)); } else { g.DrawRectangle(new Pen(Color.Yellow, 2), new Rectangle(xpos, ypos, 16, 16)); } } else { g.DrawRectangle(new Pen(Color.Yellow, 2), new Rectangle(xpos, ypos, 16, 16)); } } } } SelectedMapTiles.Add(new MapTile(i, Bitmap2BitmapSource(createdBitmap))); } }