/// <summary> /// Extracts the tileset. /// </summary> /// <param name="chipsetBitmap">The chipset bitmap.</param> /// <returns>Tileset in XP format.</returns> private Bitmap ExtractTileset(Bitmap chipsetBitmap) { // There is own background color tiles in chipset for top and low layers Color lowLayerBackgroundColor = chipsetBitmap.GetPixel(368, 112); Color topLayerBackgroundColor = chipsetBitmap.GetPixel(288, 128); Bitmap destinationBitmap = new Bitmap(128, 768); using (Graphics graphics = GraphicsUtils.GetGraphicsForScaling(destinationBitmap)) { // Low layer tiles Bitmap temporaryBitmap = chipsetBitmap.Clone(new Rectangle(192, 0, 96, 256), PixelFormat.DontCare); temporaryBitmap.MakeTransparent(lowLayerBackgroundColor); graphics.DrawImage(temporaryBitmap, new Rectangle(0, 0, 96, 256)); temporaryBitmap.Dispose(); temporaryBitmap = chipsetBitmap.Clone(new Rectangle(288, 0, 96, 128), PixelFormat.DontCare); temporaryBitmap.MakeTransparent(lowLayerBackgroundColor); graphics.DrawImage(temporaryBitmap, new Rectangle(0, 256, 96, 128)); temporaryBitmap.Dispose(); // Top layer tiles temporaryBitmap = chipsetBitmap.Clone(new Rectangle(288, 128, 96, 128), PixelFormat.DontCare); temporaryBitmap.MakeTransparent(topLayerBackgroundColor); graphics.DrawImage(temporaryBitmap, new Rectangle(0, 384, 96, 128)); temporaryBitmap.Dispose(); temporaryBitmap = chipsetBitmap.Clone(new Rectangle(384, 0, 96, 256), PixelFormat.DontCare); temporaryBitmap.MakeTransparent(topLayerBackgroundColor); graphics.DrawImage(temporaryBitmap, new Rectangle(0, 512, 96, 256)); temporaryBitmap.Dispose(); // Adding center tiles from autotiles for easier use foreach (BitmapRelationMap bitmapRelationMap in tilesBitmapRelationMaps) { temporaryBitmap = chipsetBitmap.Clone(bitmapRelationMap.SourceRectangle, PixelFormat.DontCare); graphics.DrawImage(temporaryBitmap, bitmapRelationMap.DestinationRectangle); temporaryBitmap.Dispose(); } } // XP tiles are twice the size of 2000 tiles so they need to scaled up Bitmap scaledBitmap = new Bitmap(256, 768 * 2); using (Graphics scaleGraphics = GraphicsUtils.GetGraphicsForScaling(scaledBitmap)) { scaleGraphics.DrawImage(destinationBitmap, new Rectangle(0, 0, 256, 768 * 2)); } destinationBitmap.Dispose(); return(scaledBitmap); }