public void GifStuff(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.F4))
            {
                //only send a frame every 250ms
                lastUpdate += gameTime.ElapsedGameTime.TotalMilliseconds;
                if (lastUpdate > 30)
                {
                    gifSaveRequested = true;
                    gif.AddFrame(30);
                    Debug.Log("added frame", Debug.LogType.Warning);
                    lastUpdate = 0;
                }
            }
            else if (gifSaveRequested)
            {
                Debug.Log("Saving gif", Debug.LogType.Warning);
                gifThread = new Thread(() => gif.WriteAllFrames());

                if (!gifThread.IsAlive)
                {
                    gifThread.Start();
                }
                else
                {
                    gifThread.Join();
                    Debug.Log("Saved Gif", Debug.LogType.Error);
                }

                gifSaveRequested = false;
            }
        }
Exemple #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.F12))
            {
                //only send a frame every 250ms
                lastUpdate += gameTime.ElapsedGameTime.TotalMilliseconds;
                if (lastUpdate > 250)
                {
                    gifSaveRequested = true;
                    gif.AddFrame(250);
                    lastUpdate = 0;
                }
            }
            else if (gifSaveRequested)
            {
                gif.WriteAllFrames();
                gifSaveRequested = false;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.F9))
            {
                if (!doSingleScreenshot)
                {
                    ssh.SaveScreenshot();
                    doSingleScreenshot = true;
                }
            }
            if (Keyboard.GetState().IsKeyUp(Keys.F9))
            {
                doSingleScreenshot = false;
            }


            // TODO: Add your update logic here
            rot += .05f;
            if (rot > 180)
            {
                rot = 0;
            }


            base.Update(gameTime);
        }
        private void Converttogif_btn_click(object sender, RoutedEventArgs e)
        {
            VideoFileReader videoreader = new VideoFileReader();

            // open video file
            videoreader.Open(openFileDialog1.FileName.ToString());


            GifBitmapEncoder thegifencoder = new GifBitmapEncoder();

            string filename = "thegiffile.gif";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            using (var gif = File.OpenWrite("thegiffile.gif"))
                using (var encoder = new GifMaker(gif))       // customlibs


                    for (int i = 0; i < framecount; i++)
                    {
                        Bitmap videoFrame = videoreader.ReadVideoFrame();
                        //insert jpeg commpression here.

                        BitmapSource imagesrc = Converttobmpscr(videoFrame);

                        MemoryStream ms = new MemoryStream(); //saving to memory instead of file

                        JpegBitmapEncoder jpegencoder = new JpegBitmapEncoder();
                        jpegencoder.FlipHorizontal = horizontalflip;
                        jpegencoder.FlipVertical   = verticalflip;
                        jpegencoder.QualityLevel   = qualitylevel;
                        jpegencoder.Rotation       = rotationselected;
                        jpegencoder.Frames.Add(BitmapFrame.Create(imagesrc));
                        jpegencoder.Save(ms);

                        System.Drawing.Image compr_img = System.Drawing.Image.FromStream(ms);

                        //Bitmap compr_frame = new Bitmap(compr_img);

                        if (i % framesskipped == 0)
                        {
                            //IntPtr bmp = compr_frame.GetHbitmap();
                            //BitmapSource src = Imaging.CreateBitmapSourceFromHBitmap(
                            //bmp,
                            //IntPtr.Zero,
                            //Int32Rect.Empty,
                            //BitmapSizeOptions.FromEmptyOptions());
                            //thegifencoder.Frames.Add(BitmapFrame.Create(src));

                            encoder.AddFrame(compr_img);
                        }

                        videoFrame.Dispose();
                        jpegencoder = null;
                    }

            videoreader.Close();

            //using (FileStream fs = new FileStream("thegiffile.gif", FileMode.Create))            // windows libs
            //{
            //    thegifencoder.Save(fs);
            //}

            thegifencoder = null;
        }