Example #1
0
        /// <summary>
        /// Saves an <see cref="Texture"/> to file.
        /// </summary>
        /// <param name="img">The <see cref="System.Drawing.Image"/> to save.</param>
        /// <param name="filePath">The file path to save the file to.</param>
        protected virtual void SaveTexture(Image img, string filePath)
        {
            // Scale to 10% or 20 if it's a small map
            float scaledPercent = ((float)10 / 100);

            if (img.Height < 1300)
            {
                scaledPercent = ((float)20 / 100);
            }
            var newWidth  = (int)(img.Width * scaledPercent).Clamp(1, 2048);
            var newHeight = (int)(img.Height * scaledPercent).Clamp(1, 2048);
            var newImg    = img.CreateScaled(newWidth, newHeight, true, null, null);

            newImg.SetResolution(img.HorizontalResolution, img.VerticalResolution);
            newImg.Save(filePath, ImageFormat.Png);
        }