Beispiel #1
0
        /// <summary>
        /// Saves the open world as an image
        /// </summary>
        void SaveAsImage(string saveLocation)
        {
            var settings = OpenWorld.Settings;

            using (var image = new Bitmap(settings.CanvasSize.Width, settings.CanvasSize.Height))
                using (var graphics = Graphics.FromImage(image))
                {
                    // optimize the drawing
                    graphics.InterpolationMode =
                        System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                    graphics.SmoothingMode =
                        System.Drawing.Drawing2D.SmoothingMode.None;
                    graphics.PixelOffsetMode =
                        System.Drawing.Drawing2D.PixelOffsetMode.None;
                    graphics.CompositingQuality =
                        System.Drawing.Drawing2D.CompositingQuality.HighSpeed;

                    Rectangle drawRect = new Rectangle(0, 0,
                                                       settings.TileSize.Width, settings.TileSize.Height);

                    for (int x = 0; x < settings.WorldSize.Width; x++, drawRect.X += settings.TileSize.Width)
                    {
                        // reset the y position after each x iteration
                        drawRect.Y = 0;
                        for (int y = 0; y < settings.WorldSize.Height; y++, drawRect.Y += settings.TileSize.Height)
                        {
                            for (int i = 0; i < OpenWorld.LayerCount; i++)
                            {
                                WorldTile tile = OpenWorld.GetTile(x, y, i);

                                // don't need to draw it
                                if (tile == null)
                                {
                                    continue;
                                }

                                graphics.DrawImage(OpenWorld.GetTileset(tile.Tileset).Image,
                                                   drawRect, tile.GetRectangleSystem(settings.TileSize), GraphicsUnit.Pixel);
                            }
                        }
                    }

                    image.Save(saveLocation);
                }
        }