コード例 #1
0
        // IMPORTANT: This method is SLOOOOOOOWWWWWW....
        void DebugEmitImages(GraphicsDevice graphicsDevice)
        {
            var loadHelper = new SimpleTextureLoadHelper(graphicsDevice);

            for (int i = 0; i < offsets.Length - 1; i++)
            {
                using (var bundle = new ImageBundle())
                {
                    bundle.ReadAllImages(texturePackageData, offsets[i], loadHelper);

                    for (int t = 0; t < bundle.textures.Length; t++)
                    {
                        var path = Path.Combine("ImageBundles", names[i] + " (" + t + ").gif");
                        Directory.CreateDirectory(Path.GetDirectoryName(path));

                        Animation animation = Animation.CreateSingleSprite(new Sprite(bundle.textures[t]));
                        using (var fs = File.Create(path))
                        {
                            // Because Texture2D.SaveAsPng leaks memory. :(
                            GifWriter gifWriter = new GifWriter();
                            gifWriter.SetStream(fs);
                            gifWriter.WriteAnimation(animation);
                            gifWriter.CloseStream();
                        }
                    }
                }
            }
        }
コード例 #2
0
        private MemoryStream GenerateGif()
        {
            int frameDelay = 500;

            if (!string.IsNullOrEmpty(tbFrameDelay.Text))
            {
                frameDelay = Convert.ToInt32(tbFrameDelay.Text);
            }

            MemoryStream mS        = new MemoryStream();
            GifWriter    gifWriter = new GifWriter(mS, frameDelay);

            for (int i = 0; i < listMage.Count(); i++)
            {
                gifWriter.WriteFrame(listMage[i].image);
            }

            if (cB_Forward.Checked)
            {
                for (int i = listMage.Count() - 2; i > 0; i--)
                {
                    gifWriter.WriteFrame(listMage[i].image);
                }
            }

            return(mS);
        }
コード例 #3
0
        /// <summary>
        /// HelmsDeepButton is a Static method that resets the etire GIF drawing process,
        /// resets all cells, redraws each cell, and prints a specified ammount of frames,
        /// both to a form passed and to an output 'Output.gif' file.
        /// </summary>
        /// <param name="f">The form to draw the new frames to</param>
        /// <param name="frames">The ammount of frames to print</param>
        public static void HelmsDeepButton(Form1 f, int frames = 20)
        {
            Stream       s    = File.Create("Output.gif");
            StreamWriter sw   = new StreamWriter(s);
            GifWriter    gw   = new GifWriter(s, 350, 1);
            Random       rand = new Random();

            FillCells();
            Bitmap m = new Bitmap(400, 400);

            //Graphics g = Graphics.FromImage(m);
            DisplayCells(f, rand, m);
            Graphics gg = f.CreateGraphics();

            gg.DrawImage(new Bitmap("Help.png"), 400, 50);
            gg.Dispose();
            for (int i = 0; i < frames; i++)
            {
                Debug.WriteLine(" I is " + i);
                Globals.PrintCells();
                SetUpSiegeAnimation(rand);
                RunAnimation();
                DisplayCells(f, rand, m, i);
                m.Save("temp.png", ImageFormat.Png);
                Globals.PrintCells();
                gw.WriteFrame(m);
                Thread.Sleep(1000);
            }
            //g.Dispose();
            m.Dispose();
            gw.Dispose();
            s.Close();
        }
コード例 #4
0
    private void ConvertCaptureToGif(string path)
    {
        string outputPath = Path.Combine(path, "capture.gif");

        session.Video = Path.Combine(session.Video, "capture.gif");
        DataService.Instance.UpdateSession(session);

        var gifWriter = new GifWriter(outputPath);

        // Find capture files
        var imageFiles = Directory.GetFiles(path).Where(file => file.Substring(file.Length - 4) == ".png").ToList();

        imageFiles.Sort();

        foreach (var imageFile in imageFiles)
        {
            var image = Image.FromFile(imageFile);
            gifWriter.WriteFrame(image);

            // Delete the file
            image.Dispose();
            File.Delete(imageFile);
        }

        gifWriter.Dispose();
    }
コード例 #5
0
        void ChooseFile()
        {
            var dlog = new SaveFileDialog();

            dlog.OverwritePrompt = true;
            dlog.DefaultExt      = "gif";
            dlog.AddExtension    = true;
            var result = dlog.ShowDialog();

            switch (result)
            {
            case DialogResult.OK:
            case DialogResult.Yes:
            {
                if (_outputFile != null)
                {
                    _outputFile.Dispose();
                }
                _outputFile = new GifWriter(dlog.FileName, new Size(Width - 21, Height - 31), true);
                UpdateOverlay();
                break;
            }

            default:
                return;
            }
        }
コード例 #6
0
        IVideoFileWriter GetVideoFileWriter(IImageProvider ImgProvider)
        {
            var selectedVideoSourceKind = VideoViewModel.SelectedVideoSourceKind;
            var encoder = VideoViewModel.SelectedCodec;

            IVideoFileWriter videoEncoder = null;

            encoder.Quality = VideoViewModel.Quality;

            if (encoder.Name == "Gif")
            {
                if (GifViewModel.Unconstrained)
                {
                    _recorder = new UnconstrainedFrameRateGifRecorder(
                        new GifWriter(_currentFileName,
                                      Repeat: GifViewModel.Repeat ? GifViewModel.RepeatCount : -1),
                        ImgProvider);
                }

                else
                {
                    videoEncoder = new GifWriter(_currentFileName, 1000 / VideoViewModel.FrameRate,
                                                 GifViewModel.Repeat ? GifViewModel.RepeatCount : -1);
                }
            }

            else if (selectedVideoSourceKind != VideoSourceKind.NoVideo)
            {
                videoEncoder = new AviWriter(_currentFileName, encoder);
            }
            return(videoEncoder);
        }
コード例 #7
0
    /// <summary>
    /// Resizes animated image in GIF format
    /// </summary>
    private static void ResizeAnimatedGif()
    {
        const int width  = 200;
        const int height = 50;

        using (var reader = new GifReader("../../../../_Output/WriteAnimatedGif.gif"))
        {
            var kX = (float)width / (float)reader.Width;
            var kY = (float)height / (float)reader.Height;

            using (var writer = new GifWriter("../../../../_Output/ResizeAnimatedGif.gif"))
            {
                // Copy general properties of the source file
                writer.BackgroundIndex = reader.BackgroundEntryIndex;
                writer.Palette         = reader.Palette;
                writer.PlaybackCount   = reader.PlaybackCount;

                for (int i = 0; i < reader.Frames.Count; i++)
                {
                    // Read a frame
                    using (var frame = (GifFrame)reader.Frames[i])
                        using (var bitmap = frame.GetBitmap())
                        {
                            // Preserve the original palette
                            ColorPalette palette = bitmap.Palette;
                            // Preserve the original pixel format
                            PixelFormat pixelFormat = bitmap.PixelFormat;

                            // Convert the bitmap to a non-indexed format
                            bitmap.ColorManagement.Convert(Aurigma.GraphicsMill.ColorSpace.Rgb, true, false);

                            // Resize the bitmap in a low quality mode to prevent noise
                            var newWidth  = Math.Max(1, (int)((float)bitmap.Width * kX));
                            var newHeight = Math.Max(1, (int)((float)bitmap.Height * kY));
                            bitmap.Transforms.Resize(newWidth, newHeight, ResizeInterpolationMode.Low);

                            // Return to the indexed format
                            bitmap.ColorManagement.Palette = palette;
                            bitmap.ColorManagement.Convert(pixelFormat);

                            // Copy frame settings
                            writer.FrameOptions.Left           = (ushort)((float)frame.Left * kX);
                            writer.FrameOptions.Top            = (ushort)((float)frame.Top * kY);
                            writer.FrameOptions.Delay          = frame.Delay;
                            writer.FrameOptions.DisposalMethod = frame.DisposalMethod;

                            // Add the frame
                            Pipeline.Run(bitmap + writer);
                        }
                }
            }
        }

        // BUGBUG

        /*
         * Should we move it to the A.08 GIF Format project?
         */
    }
コード例 #8
0
        /// <summary>
        /// Creates a new instance of <see cref="VfrGifRecorder"/>.
        /// </summary>
        /// <param name="encoder">The <see cref="GifWriter"/> to write into.</param>
        /// <param name="imageProvider">The <see cref="IImageProvider"/> providing the individual frames.</param>
        /// <exception cref="ArgumentNullException"><paramref name="encoder"/> or <paramref name="imageProvider"/> is null.</exception>
        public VfrGifRecorder(GifWriter encoder, IImageProvider imageProvider)
        {
            // Init Fields
            _imageProvider = imageProvider ?? throw new ArgumentNullException(nameof(imageProvider));
            _videoEncoder  = encoder ?? throw new ArgumentNullException(nameof(encoder));

            // Not Actually Started, Waits for _continueCapturing to be Set
            _recordTask = Task.Factory.StartNew(Record);
        }
コード例 #9
0
 /// <summary>
 /// Reads image in JPEG format, converts to palette-based pixel format, and saves to GIF format
 /// using memory-friendly Pipeline API
 /// </summary>
 private static void WriteGifMemoryFriendly(string inputPath, string outputPath)
 {
     using (var reader = ImageReader.Create(inputPath))
         using (var colorConverter = new ColorConverter(PixelFormat.Format8bppIndexed))
             using (var writer = new GifWriter(outputPath))
             {
                 Pipeline.Run(reader + colorConverter + writer);
             }
 }
コード例 #10
0
        private void Button_ClickGifExporter(object sender, RoutedEventArgs e)
        {
            if (Logger.Loggeractiv)
            {
                Logger.Log("\n>>Button_ClickGifExporter start");
            }
            ListBox listBox = this.Get <ListBox>("TGXImageListBox");

            if (listBox.SelectedItems == null || listBox.SelectedItems.Count == 0)
            {
                return;
            }
            var filewithoutgm1ending = vm.File.FileHeader.Name.Replace(".gm1", "");

            if (!Directory.Exists(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\Gif"))
            {
                Directory.CreateDirectory(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\Gif");
            }


            Stream    stream = new FileStream(vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\Gif\\ImageAsGif.gif", FileMode.Create);
            GifWriter gif    = new GifWriter(stream, vm.Delay, 0);

            foreach (var img in listBox.SelectedItems)
            {
                if (gif.DefaultWidth < ((Image)img).Source.PixelSize.Width)
                {
                    gif.DefaultWidth = ((Image)img).Source.PixelSize.Width;
                }
                if (gif.DefaultHeight < ((Image)img).Source.PixelSize.Height)
                {
                    gif.DefaultHeight = ((Image)img).Source.PixelSize.Height;
                }
            }

            foreach (var img in listBox.SelectedItems)
            {
                Stream imgStream = new MemoryStream();
                ((Image)img).Source.Save(imgStream);
                System.Drawing.Image imageGif = System.Drawing.Image.FromStream(imgStream);
                gif.WriteFrame(imageGif);
            }
            stream.Flush();
            stream.Dispose();

            if (vm.UserConfig.OpenFolderAfterExport)
            {
                Process.Start("explorer.exe", vm.UserConfig.WorkFolderPath + "\\" + filewithoutgm1ending + "\\Gif");
            }
            if (Logger.Loggeractiv)
            {
                Logger.Log("\n>>Button_ClickGifExporter end");
            }
        }
コード例 #11
0
        public async Task Writes_Correct_Version_Bytes(GifVersion version, byte[] expectedBytes)
        {
            var stream = new MemoryStream();
            var writer = new GifWriter(stream);

            await writer.WriteVersionAsync(version);

            var writtenBytes = stream.ToArray();

            CollectionAssert.AreEqual(expectedBytes, writtenBytes);
        }
コード例 #12
0
    private static void CreateGif(IEnumerable <int[, ]> boards, Func <int[, ], Image> BoardToImage)
    {
        var stream    = new FileStream("./test.gif", FileMode.OpenOrCreate);
        var gifWriter = new GifWriter(stream);

        foreach (var b in boards)
        {
            gifWriter.WriteFrame(BoardToImage(b), 100);
        }

        gifWriter.Dispose();
        stream.Dispose();
    }
コード例 #13
0
            public void write(Writer writer)
            {
                byte[] gifData;
                using (var gifStream = new System.IO.MemoryStream())
                {
                    GifWriter gWriter = new GifWriter(gifStream);
                    gWriter.WriteFrame(image);
                    // image.Save(gifStream, ImageFormat.Gif);
                    gifData = gifStream.ToArray();
                }
                gifData = gifData.Skip(13).ToArray();

                writer.Write((uint)gifData.Length + 4);
                writer.Write(gifData);
            }
コード例 #14
0
    /// <summary>
    /// Resizes animated image in GIF format
    /// </summary>
    private static void ResizesAnimatedGif()
    {
        using (var reader = new GifReader("../../../../_Output/WriteAnimatedGif.gif"))
            using (var writer = new GifWriter("../../../../_Output/ResizesAnimatedGif.gif"))
            {
                // Copy general properties of the source file
                writer.BackgroundIndex = reader.BackgroundEntryIndex;
                writer.Palette         = reader.Palette;
                writer.PlaybackCount   = reader.PlaybackCount;

                for (int i = 0; i < reader.Frames.Count; i++)
                {
                    // Read a frame
                    using (var frame = (GifFrame)reader.Frames[i])
                        using (var bitmap = frame.GetBitmap())
                        {
                            // Preserve the original palette
                            ColorPalette palette = bitmap.Palette;
                            // Preserve the original pixel format
                            PixelFormat pixelFormat = bitmap.PixelFormat;

                            // Convert the bitmap to a non-indexed format
                            bitmap.ColorManagement.Convert(Aurigma.GraphicsMill.ColorSpace.Rgb, true, false);

                            // Resize the bitmap in a high quality mode
                            bitmap.Transforms.Resize(frame.Width / 2, frame.Height / 2, ResizeInterpolationMode.High);

                            // Return to the indexed format
                            bitmap.Palette = palette;
                            bitmap.ColorManagement.Convert(pixelFormat);

                            // Copy frame delay
                            writer.FrameOptions.Delay = frame.Delay;

                            // Add the frame
                            Pipeline.Run(bitmap + writer);
                        }
                }
            }

        // BUGBUG

        /*
         * Может тоже в GIF Format перенести?
         */
    }
コード例 #15
0
    /// <summary>
    /// Writes simple animated image in GIF format
    /// </summary>
    private static void WriteAnimatedGif()
    {
        using (var writer = new GifWriter("../../../../_Output/WriteAnimatedGif.gif"))
        {
            writer.Width              = 400;
            writer.Height             = 100;
            writer.FrameOptions.Delay = 25;

            for (int i = 0; i < 400; i += 25)
            {
                var bitmap = new Bitmap(400, 100, PixelFormat.Format24bppRgb, RgbColor.Yellow);

                using (var graphics = bitmap.GetAdvancedGraphics())
                {
                    graphics.FillEllipse(new SolidBrush(RgbColor.Green), new System.Drawing.RectangleF(i, 0, 100, 100));
                }

                bitmap.ColorManagement.Convert(PixelFormat.Format8bppIndexed);

                Pipeline.Run(bitmap + writer);
            }
        }
    }
コード例 #16
0
        void StartRecording()
        {
            var SelectedAudioSourceId   = AudioSettings.SelectedAudioSourceId;
            var SelectedVideoSourceKind = VideoSettings.SelectedVideoSourceKind;
            var SelectedVideoSource     = VideoSettings.SelectedVideoSource;
            var Encoder = VideoSettings.Encoder;

            Duration = OtherSettings.CaptureDuration;
            Delay    = OtherSettings.StartDelay;

            if (Duration != 0 && (Delay * 1000 > Duration))
            {
                Status.Content = "Delay cannot be greater than Duration";
                SystemSounds.Asterisk.Play();
                return;
            }

            if (OtherSettings.MinimizeOnStart)
            {
                WindowState = WindowState.Minimized;
            }

            VideoSettings.Instance.VideoSourceKindBox.IsEnabled = false;
            VideoSettings.Instance.VideoSourceBox.IsEnabled     = SelectedVideoSourceKind == VideoSourceKind.Window;

            // UI Buttons
            RecordButton.ToolTip  = "Stop";
            RecordButton.IconData = (RectangleGeometry)FindResource("StopIcon");

            ReadyToRecord = false;

            int temp;

            string Extension = SelectedVideoSourceKind == VideoSourceKind.NoVideo
                ? (AudioSettings.EncodeAudio && int.TryParse(SelectedAudioSourceId, out temp) ? ".mp3" : ".wav")
                : (Encoder.Name == "Gif" ? ".gif" : ".avi");

            lastFileName = Path.Combine(OutPath.Text, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + Extension);

            Status.Content = Delay > 0 ? string.Format("Recording from t={0}ms...", Delay) : "Recording...";

            DTimer.Stop();
            Seconds             = Minutes = 0;
            TimeManager.Content = "00:00";

            DTimer.Start();

            int AudioBitRate = App.IsLamePresent ? Mp3EncoderLame.SupportedBitRates[AudioSettings.AudioQuality] : 0;

            IAudioProvider AudioSource = null;
            WaveFormat     wf          = new WaveFormat(44100, 16, AudioSettings.Stereo ? 2 : 1);

            if (SelectedAudioSourceId != "-1")
            {
                int i;
                if (int.TryParse(SelectedAudioSourceId, out i))
                {
                    AudioSource = new WaveIn(i, VideoSettings.FrameRate, wf);
                }
                else
                {
                    AudioSource = new WasapiLoopbackCapture(WasapiAudioDevice.Get(SelectedAudioSourceId), true);
                    wf          = AudioSource.WaveFormat;
                }
            }

            #region ImageProvider
            IImageProvider ImgProvider = null;

            Func <System.Windows.Media.Color, System.Drawing.Color> ConvertColor = (C) => System.Drawing.Color.FromArgb(C.A, C.R, C.G, C.B);

            var mouseKeyHook = new MouseKeyHook(OtherSettings.CaptureClicks,
                                                OtherSettings.CaptureKeystrokes);

            if (SelectedVideoSourceKind == VideoSourceKind.Window)
            {
                var Src = SelectedVideoSource as WindowVSLI;

                if (Src.Handle == RegionSelector.Instance.Handle &&
                    OtherSettings.StaticRegionCapture)
                {
                    ImgProvider = new StaticRegionProvider(RegionSelector.Instance,
                                                           cursor,
                                                           mouseKeyHook);
                    VideoSettings.Instance.VideoSourceBox.IsEnabled = false;
                }
                else
                {
                    ImgProvider = new WindowProvider(() => (VideoSettings.SelectedVideoSource as WindowVSLI).Handle,
                                                     ConvertColor(VideoSettings.BackgroundColor),
                                                     cursor,
                                                     mouseKeyHook);
                }
            }
            else if (SelectedVideoSourceKind == VideoSourceKind.Screen)
            {
                ImgProvider = new ScreenProvider((SelectedVideoSource as ScreenVSLI).Screen,
                                                 cursor,
                                                 mouseKeyHook);
            }
            #endregion

            #region VideoEncoder
            IVideoFileWriter VideoEncoder = null;

            if (Encoder.Name == "Gif")
            {
                if (GifSettings.UnconstrainedGif)
                {
                    Recorder = new UnconstrainedFrameRateGifRecorder(
                        new GifWriter(lastFileName,
                                      Repeat: GifSettings.GifRepeat ? GifSettings.GifRepeatCount : -1),
                        ImgProvider);
                }

                else
                {
                    VideoEncoder = new GifWriter(lastFileName, 1000 / VideoSettings.FrameRate,
                                                 GifSettings.GifRepeat ? GifSettings.GifRepeatCount : -1);
                }
            }

            else if (SelectedVideoSourceKind != VideoSourceKind.NoVideo)
            {
                VideoEncoder = new AviWriter(lastFileName,
                                             ImgProvider,
                                             Encoder,
                                             VideoSettings.VideoQuality,
                                             VideoSettings.FrameRate,
                                             AudioSource,
                                             AudioBitRate == 0 ? null
                                                                : new Mp3EncoderLame(wf.Channels, wf.SampleRate, AudioBitRate));
            }
            #endregion

            if (Recorder == null)
            {
                if (SelectedVideoSourceKind == VideoSourceKind.NoVideo)
                {
                    if (AudioSettings.EncodeAudio)
                    {
                        Recorder = new AudioRecorder(AudioSource, new EncodedAudioFileWriter(lastFileName, new Mp3EncoderLame(wf.Channels, wf.SampleRate, AudioBitRate)));
                    }
                    else
                    {
                        Recorder = new AudioRecorder(AudioSource, new WaveFileWriter(lastFileName, wf));
                    }
                }
                else
                {
                    Recorder = new Recorder(VideoEncoder, ImgProvider, AudioSource);
                }
            }

            Recorder.RecordingStopped += (E) => Dispatcher.Invoke(() =>
            {
                OnStopped();

                if (E != null)
                {
                    Status.Content = "Error";
                    MessageBox.Show(E.ToString());
                }
            });

            Recorder.Start(Delay);

            Recent.Add(lastFileName,
                       VideoEncoder == null ? RecentItemType.Audio : RecentItemType.Video);
        }
コード例 #17
0
ファイル: MainViewModel.cs プロジェクト: MathewSachin/Captura
        IVideoFileWriter GetVideoFileWriter(IImageProvider ImgProvider)
        {
            var selectedVideoSourceKind = VideoViewModel.SelectedVideoSourceKind;
            var encoder = VideoViewModel.SelectedCodec;

            IVideoFileWriter videoEncoder = null;
            encoder.Quality = VideoViewModel.Quality;

            if (encoder.Name == "Gif")
            {
                if (GifViewModel.Unconstrained)
                    _recorder = new UnconstrainedFrameRateGifRecorder(
                        new GifWriter(_currentFileName,
                            Repeat: GifViewModel.Repeat ? GifViewModel.RepeatCount : -1),
                        ImgProvider);

                else
                    videoEncoder = new GifWriter(_currentFileName, 1000/VideoViewModel.FrameRate,
                        GifViewModel.Repeat ? GifViewModel.RepeatCount : -1);
            }

            else if (selectedVideoSourceKind != VideoSourceKind.NoVideo)
                videoEncoder = new AviWriter(_currentFileName, encoder);
            return videoEncoder;
        }
コード例 #18
0
        private void button1_Click(object sender, EventArgs e)
        {
            framesDic = new Dictionary <int, Bitmap>();

            double minX = double.Parse(textBox1.Text);
            double minY = double.Parse(textBox2.Text);

            double maxX = double.Parse(textBox3.Text);
            double maxY = double.Parse(textBox4.Text);

            double tomaxY = double.Parse(textBox5.Text);
            double tomaxX = double.Parse(textBox6.Text);

            double tominY = double.Parse(textBox7.Text);
            double tominX = double.Parse(textBox8.Text);

            int frames = int.Parse(textBox9.Text);

            double linearSum = GetLinearSum(frames);

            double xMinParticle = ((double)(tominX - minX) / linearSum);
            double xMaxParticle = ((double)(tomaxX - maxX) / linearSum);
            double yMinParticle = ((double)(tominY - minY) / linearSum);
            double yMaxParticle = ((double)(tomaxY - maxY) / linearSum);

            int linearSumOFrames = GetLinearSum(frames);

            int   k      = int.Parse(textBox11.Text);
            float power  = float.Parse(textBox12.Text);
            float power2 = float.Parse(textBox15.Text);
            float light  = float.Parse(textBox16.Text);

            int startHue = int.Parse(textBox13.Text);
            int endHue   = int.Parse(textBox14.Text);

            int width  = int.Parse(textBox17.Text);
            int height = int.Parse(textBox18.Text);

            int cpusCount = Environment.ProcessorCount;
            var threads   = new List <Thread>();

            for (int i = 0; i < frames; i++)
            {
                int    key   = i;
                double _minX = minX;
                double _maxX = maxX;
                double _minY = minY;
                double _maxY = maxY;

                Thread thread = new Thread(new ThreadStart(() => framesDic.Add(key, new Mandelbrot().GetImage(width, height, _minX, _maxX, _minY, _maxY, k, power, startHue, endHue, power2, light))));
                threads.Add(thread);
                thread.Start();
                cpusCount--;

                double toAddminX = xMinParticle * (double)(frames - i);
                double toAddmaxX = xMaxParticle * (double)(frames - i);
                double toAddminY = yMinParticle * (double)(frames - i);
                double toAddmaxY = yMaxParticle * (double)(frames - i);

                minX += toAddminX;
                minY += toAddminY;
                maxX += toAddmaxX;
                maxY += toAddmaxY;

                if (cpusCount == 0 || i == frames - 1)
                {
                    foreach (var thrd in threads)
                    {
                        thrd.Join();
                    }
                    cpusCount = Environment.ProcessorCount;
                }
            }

            var orderedFrames = framesDic.OrderBy(x => x.Key).Select(x => x.Value);

            if (checkBox1.Checked)
            {
                using (MemoryStream msGif = new MemoryStream())
                {
                    GifWriter gifWriter = new GifWriter(msGif, 50, -1);

                    foreach (var bitmap in orderedFrames)
                    {
                        using (MemoryStream msImage = new MemoryStream())
                        {
                            bitmap.Save(msImage, System.Drawing.Imaging.ImageFormat.Png);
                            gifWriter.WriteFrame(Image.FromStream(msImage));
                        }
                    }

                    File.WriteAllBytes("test.gif", msGif.GetBuffer());
                }
            }
            else
            {
                foreach (var kvp in framesDic)
                {
                    using (FileStream msImage = new FileStream(kvp.Key + ".png", FileMode.Create))
                    {
                        kvp.Value.Save(msImage, System.Drawing.Imaging.ImageFormat.Png);
                    }
                }
            }
        }