コード例 #1
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);
        }
コード例 #2
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();
        }
コード例 #3
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();
    }
コード例 #4
0
        private void Record()
        {
            try
            {
                IBitmapFrame lastFrame = null;

                while (!_stopCapturing.WaitOne(0) && _continueCapturing.WaitOne())
                {
                    var frame = _imageProvider.Capture();

                    var delay = (int)_timing.Elapsed.TotalMilliseconds;

                    _timing.Stop();
                    _timing.Start();

                    // delay is the time between this and next frame
                    if (lastFrame != null)
                    {
                        _videoEncoder.WriteFrame(lastFrame, delay);
                    }

                    lastFrame = frame.GenerateFrame();
                }
            }
            catch (Exception e)
            {
                ErrorOccurred?.Invoke(e);

                Dispose(true);
            }
        }
コード例 #5
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");
            }
        }
コード例 #6
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();
    }
コード例 #7
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);
            }
コード例 #8
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);
                    }
                }
            }
        }