コード例 #1
0
        public static string SaveAs(Bitmap image, MapGeneratorInput mapInput, ImageFileSettings fileSettings)
        {
            string fileName = GetFileNameFromSaveDialog(mapInput, fileSettings);

            image.Save(fileName, fileSettings.Format);
            return(fileName);
        }
コード例 #2
0
        public static string Save(Bitmap image, MapGeneratorInput mapInput, ImageFileSettings fileSettings)
        {
            string fileName = GenerateAutoSaveFileName(mapInput, fileSettings);

            image.Save(fileName, fileSettings.Format);
            return(fileName);
        }
コード例 #3
0
        // returns a file name with the specified prefix and auto increased number postfix as the filename
        public static string GenerateAutoSaveFileName(MapGeneratorInput mapInput, ImageFileSettings fileSettings)
        {
            // Get files that start with fileNamePrefix
            string[] fileList = Directory.GetFiles(Directory.GetCurrentDirectory(), fileSettings.FileNamePrefix + "*");
            // Filter out only the files matching prefix+"0000"
            // Get largest postfix number
            int postfixNum = -1;

            foreach (string file in fileList)
            {
                Match match = Regex.Match(file, fileSettings.FileNamePrefix + @"\[.+\].(\d\d\d\d).\w+");
                if (match.Success)
                {
                    int num = Int32.Parse(match.Groups[1].ToString());
                    if (num > postfixNum)
                    {
                        postfixNum = num;
                    }
                }
            }
            postfixNum++;
            string postfix = postfixNum.ToString("0000");

            return(fileSettings.FileNamePrefix + "[" + mapInput.FillRate.ToString("0.00") + " " + mapInput.FillAlgorithm + " " + mapInput.Width + " " + mapInput.Height + "]." + postfix + "." + fileSettings.Extention);
        }
コード例 #4
0
 public FormDisplay(GifGenerator gifGen, MapGeneratorInput mapInput, ImageFileSettings fileSettings)
 {
     // Windows Form 設計工具支援的必要項
     InitializeComponent();
     //Initialize variables
     GifGen       = gifGen;
     MapInput     = mapInput;
     FileSettings = fileSettings;
     // Show bitmap
     Display();
 }
コード例 #5
0
        // returns a file name with the specified prefix and auto increased number postfix as the filename
        public static string GenerateAutoSaveFileName(MapGeneratorInput mapInput, ImageFileSettings fileSettings)
        {
            string fileName = "";

            if (mapInput.FromFile == "")
            {
                string algo = "";
                switch (mapInput.FillAlgorithm)
                {
                case 0:
                    algo = "FixedCount";
                    break;

                case 1:
                    algo = "RandomCount";
                    break;

                case 2:
                    algo = string.Format("Fractal-H{0}", mapInput.H);
                    break;

                default:
                    break;
                }
                fileName = fileSettings.FileNamePrefix + algo + "-F" + mapInput.FillRate.ToString("0.00") + "-S" + mapInput.Width + "x" + mapInput.Height;
            }
            else
            {
                fileName = mapInput.FromFile.Replace(".txt", "");
            }
            // Get files that start with fileNamePrefix
            string[] fileList = Directory.GetFiles(Directory.GetCurrentDirectory(), fileName + "*");
            // Filter out only the files matching prefix+"0000"
            // Get largest postfix number
            int postfixNum = -1;

            foreach (string file in fileList)
            {
                Match match = Regex.Match(file, fileName + @"\.(\d\d\d\d)\.\w+");
                if (match.Success)
                {
                    int num = Int32.Parse(match.Groups[1].ToString());
                    if (num > postfixNum)
                    {
                        postfixNum = num;
                    }
                }
            }
            postfixNum++;
            string postfix = postfixNum.ToString("0000");

            return(fileName + "." + postfix);
        }
コード例 #6
0
        public static string GetFileNameFromSaveDialog(MapGeneratorInput mapInput, ImageFileSettings fileSettings)
        {
            // Set default file name
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.DefaultExt = fileSettings.Extention;
            saveFileDialog.Filter     = fileSettings.Filter;
            saveFileDialog.FileName   = GenerateAutoSaveFileName(mapInput, fileSettings);
            if (saveFileDialog.ShowDialog() != DialogResult.Cancel)
            {
                if (saveFileDialog.FileName == "" || saveFileDialog.FileName == null)
                {
                    MessageBox.Show("Invalid File Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    return(Regex.Match(saveFileDialog.FileName, @".+\\(\w+\.\w+)").Groups[1].ToString());
                }
            }
            return("");
        }