Beispiel #1
0
        private void ApplyNewImageButton_Click(object sender, RoutedEventArgs e)
        {
            Pause();

            #region FileName

            string pathTemp = Path.Combine(Path.GetTempPath(), @"ScreenToGif\Recording", DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"));

            if (!Directory.Exists(pathTemp))
                Directory.CreateDirectory(pathTemp);

            var fileName = Path.Combine(pathTemp, "0.bmp");

            #endregion

            ActionStack.Clear();
            ActionStack.Prepare(pathTemp);

            #region Create and Save Image

            using (var stream = new FileStream(fileName, FileMode.Create))
            {
                var scale = this.Scale();

                var bitmapSource = ImageMethods.CreateEmtpyBitmapSource(Settings.Default.NewImageColor,
                    (int)(Settings.Default.NewImageWidth * scale),
                    (int)(Settings.Default.NewImageHeight * scale), this.Dpi(), PixelFormats.Indexed1);
                var bitmapFrame = BitmapFrame.Create(bitmapSource);

                BitmapEncoder encoder = new BmpBitmapEncoder();
                encoder.Frames.Add(bitmapFrame);
                encoder.Save(stream);
                stream.Flush();
                stream.Close();
            }

            GC.Collect();

            #endregion

            ClosePanel();

            #region Adds to the List

            var frame = new FrameInfo(fileName, 66);

            LoadNewFrames(new List<FrameInfo> { frame });

            #endregion
        }
Beispiel #2
0
        private List<FrameInfo> ImportFromGif(string sourceFileName, string pathTemp)
        {
            ShowProgress(DispatcherResMessage("Editor.ImportingFrames"), 50, true);

            GifFile gifMetadata;
            var listFrames = new List<FrameInfo>();

            var decoder = ImageMethods.GetDecoder(sourceFileName, out gifMetadata) as GifBitmapDecoder;

            ShowProgress(DispatcherResMessage("Editor.ImportingFrames"), decoder.Frames.Count);

            if (decoder.Frames.Count > 1)
            {
                var fullSize = ImageMethods.GetFullSize(decoder, gifMetadata);
                int index = 0;

                BitmapSource baseFrame = null;
                foreach (var rawFrame in decoder.Frames)
                {
                    var metadata = ImageMethods.GetFrameMetadata(decoder, gifMetadata, index);

                    var bitmapSource = ImageMethods.MakeFrame(fullSize, rawFrame, metadata, baseFrame);

                    #region Disposal Method

                    switch (metadata.DisposalMethod)
                    {
                        case FrameDisposalMethod.None:
                        case FrameDisposalMethod.DoNotDispose:
                            baseFrame = bitmapSource;
                            break;
                        case FrameDisposalMethod.RestoreBackground:
                            if (ImageMethods.IsFullFrame(metadata, fullSize))
                            {
                                baseFrame = null;
                            }
                            else
                            {
                                baseFrame = ImageMethods.ClearArea(bitmapSource, metadata);
                            }
                            break;
                        case FrameDisposalMethod.RestorePrevious:
                            // Reuse same base frame
                            break;
                    }

                    #endregion

                    #region Each Frame

                    var fileName = Path.Combine(pathTemp, index + ".bmp");

                    using (var stream = new FileStream(fileName, FileMode.Create))
                    {
                        BitmapEncoder encoder = new BmpBitmapEncoder();
                        encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
                        encoder.Save(stream);
                        stream.Close();
                    }

                    //It should not throw a overflow exception because of the maximum value for the miliseconds.
                    var frame = new FrameInfo(fileName, (int)metadata.Delay.TotalMilliseconds);
                    listFrames.Add(frame);

                    UpdateProgress(index);

                    GC.Collect(1);

                    #endregion

                    index++;
                }
            }

            #region Old Way to Save the Image to the Recording Folder

            //var decoder = new GifBitmapDecoder(new Uri(sourceFileName), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);

            //int count = 0;

            //foreach (BitmapFrame bitmapFrame in decoder.Frames)
            //{
            //    var fileName = String.Format("{0}{1}.bmp", pathTemp, count);

            //    using (var stream = new FileStream(fileName, FileMode.Create))
            //    {
            //        BitmapEncoder encoder = new BmpBitmapEncoder();
            //        encoder.Frames.Add(BitmapFrame.Create(bitmapFrame));
            //        encoder.Save(stream);
            //        stream.Close();
            //    }

            //    var frame = new FrameInfo(fileName, 66);
            //    listFrames.Add(frame);

            //    count++;
            //}

            #endregion

            return listFrames;
        }
Beispiel #3
0
        private List<FrameInfo> ImportFromVideo(string fileName, string pathTemp)
        {
            int delay = 66;

            var frameList = Dispatcher.Invoke(() =>
            {
                var videoSource = new VideoSource(fileName) { Owner = this };
                var result = videoSource.ShowDialog();

                if (result.HasValue && result.Value)
                {
                    delay = videoSource.Delay;
                    return videoSource.FrameList;
                }

                return null;
            });

            if (frameList == null) return null;

            ShowProgress(DispatcherResMessage("Editor.ImportingFrames"), frameList.Count);

            #region Saves the Frames to the Disk

            var frameInfoList = new List<FrameInfo>();
            int count = 0;

            foreach (BitmapFrame frame in frameList)
            {
                var frameName = Path.Combine(pathTemp, count + DateTime.Now.ToString("hh-mm-ss") + ".bmp");

                using (var stream = new FileStream(frameName, FileMode.Create))
                {
                    BitmapEncoder encoder = new BmpBitmapEncoder();
                    encoder.Frames.Add(frame);
                    encoder.Save(stream);
                    stream.Close();
                }

                var frameInfo = new FrameInfo(frameName, delay);
                frameInfoList.Add(frameInfo);

                GC.Collect();
                count++;

                UpdateProgress(count);
            }

            #endregion

            return frameInfoList;
        }
Beispiel #4
0
        /// <summary>
        /// Makes a Yo-yo efect with the given List (List + Reverted List)
        /// </summary>
        /// <param name="list">The list to apply the efect</param>
        /// <returns>A List with the Yo-yo efect</returns>
        public static List<FrameInfo> Yoyo(List<FrameInfo> list)
        {
            var listReverted = new List<FrameInfo>(list);
            listReverted.Reverse();

            foreach (FrameInfo frame in listReverted)
            {
                File.Copy(frame.ImageLocation, frame.ImageLocation.Replace(".bmp", "R.bmp"));

                var newFrame = new FrameInfo(frame.ImageLocation.Replace(".bmp", "R.bmp"), frame.Delay, frame.CursorInfo);

                list.Add(newFrame);
            }

            return list;
        }
Beispiel #5
0
        private void ApplyTitleFrameButton_Click(object sender, RoutedEventArgs e)
        {
            #region Create and Save Image

            var fileName = ListFrames[0].ImageLocation.Replace(".bmp", "TF.bmp");
            var dpi = ListFrames[0].ImageLocation.DpiOf();
            var scaledSize = ListFrames[0].ImageLocation.ScaledSize();

            using (var stream = new FileStream(fileName, FileMode.Create))
            {
                #region Parameters

                var render = TitleFrameOverlayGrid.GetRender(dpi, scaledSize);

                var bitmapSource = ImageMethods.CreateEmtpyBitmapSource(Settings.Default.NewImageColor,
                    (int)scaledSize.Width, (int)scaledSize.Height, dpi, PixelFormats.Indexed1);

                #endregion

                #region Merge

                var drawingVisual = new DrawingVisual();
                using (DrawingContext drawingContext = drawingVisual.RenderOpen())
                {
                    drawingContext.DrawImage(bitmapSource, new Rect(0, 0, bitmapSource.Width, bitmapSource.Height));
                    drawingContext.DrawImage(render, new Rect(0, 0, render.Width, render.Height));
                }

                // Converts the Visual (DrawingVisual) into a BitmapSource
                var bmp = new RenderTargetBitmap((int)scaledSize.Width, (int)scaledSize.Height, dpi, dpi, PixelFormats.Pbgra32);
                bmp.Render(drawingVisual);

                #endregion

                var bitmapFrame = BitmapFrame.Create(bmp);

                BitmapEncoder encoder = new BmpBitmapEncoder();
                encoder.Frames.Add(bitmapFrame);
                encoder.Save(stream);
                stream.Flush();
                stream.Close();
            }

            GC.Collect();

            #endregion

            #region Adds to the List

            var frame = new FrameInfo(fileName, 500);

            ListFrames.Insert(FrameListView.SelectedIndex, frame);
            LoadNewFrames(ListFrames);

            #endregion

            ClosePanel();
        }
Beispiel #6
0
        private List<FrameInfo> ImportFromGif(string sourceFileName, string pathTemp)
        {
            var gifDecoder = new GifDecoder();
            gifDecoder.Read(sourceFileName);

            var list = ImageMethods.GetFrames(sourceFileName);

            var listFrames = new List<FrameInfo>();

            int frameCount = gifDecoder.GetFrameCount();

            ShowProgress("Importing Frames", frameCount);

            for (int index = 0; index < frameCount; index++)
            {
                #region Each Frame

                var fileName = Path.Combine(pathTemp, index + ".bmp");

                using (var stream = new FileStream(fileName, FileMode.Create))
                {
                    //var frameAux = gifDecoder.GetFrame(index);
                    var frameAux = list[index];
                    frameAux.Save(stream, ImageFormat.Png);
                    frameAux.Dispose();

                    stream.Flush();
                    stream.Close();
                }

                var frame = new FrameInfo(fileName, gifDecoder.GetDelay(index));
                listFrames.Add(frame);

                UpdateProgress(index);

                GC.Collect(1);

                #endregion
            }

            #region Old Way to Save the Image to the Recording Folder

            //var decoder = new GifBitmapDecoder(new Uri(sourceFileName), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);

            //int count = 0;

            //foreach (BitmapFrame bitmapFrame in decoder.Frames)
            //{
            //    var fileName = String.Format("{0}{1}.bmp", pathTemp, count);

            //    using (var stream = new FileStream(fileName, FileMode.Create))
            //    {
            //        BitmapEncoder encoder = new BmpBitmapEncoder();
            //        encoder.Frames.Add(BitmapFrame.Create(bitmapFrame));
            //        encoder.Save(stream);
            //        stream.Close();
            //    }

            //    var frame = new FrameInfo(fileName, 66);
            //    listFrames.Add(frame);

            //    count++;
            //}

            #endregion

            return listFrames;
        }
Beispiel #7
0
        private void NewAnimation_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            e.Handled = true;
            Pause();
            var newAnim = new Create();
            var result = newAnim.ShowDialog();

            if (!result.HasValue || result != true) return;

            #region FileName

            string pathTemp = Path.Combine(Path.GetTempPath(), @"ScreenToGif\Recording", DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"));

            if (!Directory.Exists(pathTemp))
                Directory.CreateDirectory(pathTemp);

            var fileName = Path.Combine(pathTemp, "0.bmp");

            #endregion

            ActionStack.Clear();
            ActionStack.Prepare(pathTemp);

            #region Create and Save Image

            using (var stream = new FileStream(fileName, FileMode.Create))
            {
                var bitmapSource = ImageMethods.CreateEmtpyBitmapSource(newAnim.Color, newAnim.WidthValue, newAnim.HeightValue, PixelFormats.Indexed1);
                var bitmapFrame = BitmapFrame.Create(bitmapSource);

                BitmapEncoder encoder = new BmpBitmapEncoder();
                encoder.Frames.Add(bitmapFrame);
                encoder.Save(stream);
                stream.Flush();
                stream.Close();
            }

            GC.Collect();

            #endregion

            DiscardProject_Executed(null, null);

            #region Adds to the List

            var frame = new FrameInfo(fileName, 66);

            ListFrames = new List<FrameInfo> { frame };
            LoadNewFrames(ListFrames);

            #endregion
        }
Beispiel #8
0
        /// <summary>
        /// Makes a Yo-yo efect with the given List (List + Reverted List)
        /// </summary>
        /// <param name="list">The list to apply the efect</param>
        /// <returns>A List with the Yo-yo efect</returns>
        public static List<FrameInfo> Yoyo(List<FrameInfo> list)
        {
            var listReverted = new List<FrameInfo>(list);
            listReverted.Reverse();

            var currentFolder = Path.GetDirectoryName(list[0].ImageLocation);

            foreach (var frame in listReverted)
            {
                var newPath = Path.Combine(currentFolder, list.Count + ".bmp");

                File.Copy(frame.ImageLocation, newPath);

                var newFrame = new FrameInfo(newPath, frame.Delay, frame.CursorInfo);

                list.Add(newFrame);
            }

            return list;
        }