Ejemplo n.º 1
0
        public ScreenRecording(string outputFileName, int X, int Y, int W, int H)
        {
            int delay = Convert.ToInt32(1000 / Properties.Settings.Default.framesPerSecond);

            gif = AnimatedGif.AnimatedGif.Create(outputFileName, delay);
            this.outputFileName = outputFileName;
            this.X = X;
            this.Y = Y;
            this.W = W;
            this.H = H;
        }
Ejemplo n.º 2
0
        public VideoSaver(RecorderParams Params)
        {
            this.Params = Params;
            switch (Params.fileFormat)
            {
            case FileFormat.GIF:
                var frameInterval = TimeSpan.FromSeconds(1 / (double)Params.FramesPerSecond);
                gif = AnimatedGif.AnimatedGif.Create(Params.FileName, frameInterval.Milliseconds, 1);
                break;

            case FileFormat.WEBM:
                vFWriter = new VideoFileWriter();
                vFWriter.Open(Params.FileName, Params.Width, Params.Height, Params.FramesPerSecond);
                break;
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            List <Bitmap> bitmaps  = new List <Bitmap>();
            List <Bitmap> bitmaps2 = new List <Bitmap>();

            int rayByPixel   = 1;
            int halfNbFrames = 2;

            var thread = new Thread(() =>
            {
                for (int i = 0; i < halfNbFrames; i++)
                {
                    bitmaps.Add(CreateBitmap(i, halfNbFrames, rayByPixel));
                }
            });

            var thread2 = new Thread(() =>
            {
                for (int i = halfNbFrames; i < halfNbFrames * 2; i++)
                {
                    bitmaps2.Add(CreateBitmap(i, halfNbFrames, rayByPixel));
                }
            });

            thread.Start();
            thread2.Start();
            thread.Join();
            thread2.Join();

            bitmaps.AddRange(bitmaps2);

            using (AnimatedGif.AnimatedGifCreator gif = AnimatedGif.AnimatedGif.Create("gif.gif", 100))
            {
                foreach (Bitmap bmpImage in bitmaps)
                {
                    gif.AddFrame(bmpImage);
                }
            }
        }
Ejemplo n.º 4
0
        private void PicToGif()
        {
            string fileName = string.Format("{0}/{1}.gif", txtPath.Text, DateTime.Now.ToString("yyMMdd_HHmmss"));

            //Delay time is one hundredths (1/100) of a second between frames;
            AnimatedGif.AnimatedGifCreator gif = AnimatedGif.AnimatedGif.Create(fileName, Settings.Default.Gif帧间隔);
            DirectoryInfo dirInfo = new DirectoryInfo(CombineTempPath);

            foreach (FileSystemInfo imgFile in dirInfo.GetFileSystemInfos())
            {
                Image img = Image.FromFile(imgFile.FullName);
                gif.AddFrame(img);
                img.Dispose();
            }
            gif.Dispose();
            if (Settings.Default.Is删除GIF临时文件)
            {
                Functions.DeleteDir(CombineTempPath);
            }
            if (Settings.Default.Pic截图同步到剪切板)
            {
                Clipboard.SetImage(new Bitmap(fileName));
            }
        }
Ejemplo n.º 5
0
        public static void exportGif(int scale, int delay, bool shouldFrame, int recDelay, int initialRecDelay, Rectangle?framing)
        {
            int    i    = 0;
            int    tCol = tranparentColor.ToArgb();
            string name = "GeneratedGif" + i + ".gif";
            var    path = Path.Combine(_helper.DirectoryPath, "Generated", name);

            while (File.Exists(path))
            {
                i++;
                name = "GeneratedGif" + i + ".gif";
                path = Path.Combine(_helper.DirectoryPath, "Generated", name);
            }

            int w = Game1.game1.Window.ClientBounds.Width;
            int h = Game1.game1.Window.ClientBounds.Height;

            using (FileStream f = new FileStream(path, FileMode.Create, FileAccess.ReadWrite))
                using (var gifWriter = new AnimatedGif.AnimatedGifCreator(f, delay, 0))
                {
                    if (initialRecDelay != 0)
                    {
                        Thread.Sleep(initialRecDelay);
                    }

                    while ((frames != null && frames.Count > 0) || recording)
                    {
                        Microsoft.Xna.Framework.Color[] c;
                        if (frames != null && frames.Count > 0 && frames.TryDequeue(out c))
                        {
                            using (MemoryStream m = new MemoryStream())
                            {
                                if (shouldFrame && framing.HasValue)
                                {
                                    using (Bitmap framedImage = new Bitmap(framing.Value.Width, framing.Value.Height))
                                    {
                                        for (int x = framing.Value.X; x < framing.Value.X + framing.Value.Width; x++)
                                        {
                                            for (int y = framing.Value.Y; y < framing.Value.Y + framing.Value.Height; y++)
                                            {
                                                if (c[x + (y * w)] is Microsoft.Xna.Framework.Color cXY)
                                                {
                                                    if (Color.FromArgb(cXY.A, cXY.R, cXY.G, cXY.B) is Color nc && !removeMapLayers || (nc.ToArgb() - tCol > 20))
                                                    {
                                                        framedImage.SetPixel(x - framing.Value.X, y - framing.Value.Y, nc);
                                                    }
                                                }
                                            }
                                        }
                                        gifWriter.AddFrame(framedImage, quality: AnimatedGif.GifQuality.Bit8);
                                    }
                                }
                                else
                                {
                                    using (Bitmap image = new Bitmap(w / scale, h / scale))
                                    {
                                        for (int x = 0; x < w; x++)
                                        {
                                            if (x % scale == 0)
                                            {
                                                for (int y = 0; y < h; y++)
                                                {
                                                    if (y % scale == 0)
                                                    {
                                                        if (c[x + (y * w)] is Microsoft.Xna.Framework.Color cXY)
                                                        {
                                                            if (Color.FromArgb(cXY.A, cXY.R, cXY.G, cXY.B) is Color nc && !removeMapLayers || (nc.ToArgb() - tCol > 20))
                                                            {
                                                                image.SetPixel(x / scale, y / scale, nc);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        gifWriter.AddFrame(image, quality: AnimatedGif.GifQuality.Bit8);
                                    }
                                }
                            }
                        }
                        if (recDelay != 0)
                        {
                            Thread.Sleep(recDelay);
                        }
                    }
                }

            gifThread = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            completedExport = true;
            frames          = null;
            _monitor.Log("Exported: " + name);
        }