Exemple #1
0
        internal static void Output()
        {
            var outputDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\SectionalCropper\output\";

            DirectoryController.CreateIfMissing(outputDirectory);
            foreach (var frame in Frame.Frames)
            {
                var bmpInput = new Bitmap(frame.ImageSource);
                bmpInput = bmpInput.Clone(new Rectangle(Convert.ToInt32(frame.Rectangle.Left), Convert.ToInt32(frame.Rectangle.Top), Convert.ToInt32(frame.Rectangle.Width), Convert.ToInt32(frame.Rectangle.Height)), PixelFormat.Undefined);
                var brush     = new SolidBrush(Color.Fuchsia);
                var scale     = Math.Min(Convert.ToDouble(OutputParameters.Width) / Convert.ToDouble(bmpInput.Width), Convert.ToDouble(OutputParameters.Height) / Convert.ToDouble(bmpInput.Height));
                var bmpOutput = new Bitmap(OutputParameters.Width, OutputParameters.Height);
                var graph     = Graphics.FromImage(bmpOutput);
                graph.InterpolationMode  = InterpolationMode.High;
                graph.CompositingQuality = CompositingQuality.HighQuality;
                graph.SmoothingMode      = SmoothingMode.AntiAlias;
                var scaleWidth  = (int)(bmpInput.Width * scale);
                var scaleHeight = (int)(bmpInput.Height * scale);
                graph.FillRectangle(brush, new RectangleF(0, 0, OutputParameters.Width, OutputParameters.Height));
                graph.DrawImage(bmpInput, (OutputParameters.Width - scaleWidth) / 2, (OutputParameters.Height - scaleHeight) / 2, scaleWidth, scaleHeight);
                bmpOutput.Save(outputDirectory + $"{frame.Index}.png", ImageFormat.Png);
                bmpInput.Dispose();
                bmpOutput.Dispose();
            }
        }
        internal static void Load()
        {
            var inputDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\SectionalCropper\input\";

            DirectoryController.CreateIfMissing(inputDirectory);
            Frame.Frames?.Clear();
            var files = System.IO.Directory.GetFiles(inputDirectory);

            foreach (var file in files)
            {
                Frame.Add(file);
            }
            Frame.CurrentIndex = 0;
        }
        internal static void Save()
        {
            var directory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\SectionalCropper\";

            DirectoryController.CreateIfMissing(directory);
            var lst = new List <string>();

            foreach (var frame in Frame.Frames.Where(x => x.IsKey))
            {
                lst.Add(string.Join(",", frame.Index.ToString(), frame.Rectangle.X.ToString(), frame.Rectangle.Y.ToString(), frame.Rectangle.Width.ToString(), frame.Rectangle.Height.ToString()));
            }
            using (var sw = new StreamWriter(directory + "parameters.csv"))
            {
                sw.Write(string.Join("\n", lst));
                sw.Close();
            }
        }
        internal static void Load()
        {
            var directory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\SectionalCropper\";

            DirectoryController.CreateIfMissing(directory);
            using (var sr = new StreamReader(directory + "parameters.csv"))
            {
                while (sr.Peek() != -1)
                {
                    var data  = sr.ReadLine().Split(',');
                    var frame = Frame.Frames[Convert.ToInt32(data[0])];
                    frame.IsKey = true;
                    frame.SetRectangle(Frame.RectangleVariables.Left, Convert.ToDouble(data[1]));
                    frame.SetRectangle(Frame.RectangleVariables.Top, Convert.ToDouble(data[2]));
                    frame.SetRectangle(Frame.RectangleVariables.Width, Convert.ToDouble(data[3]));
                    frame.SetRectangle(Frame.RectangleVariables.Height, Convert.ToDouble(data[4]));
                }
                sr.Close();
            }
        }