示例#1
0
        public void SaveAsGIF(string path, GIFQuality quality)
        {
            if (imgCache != null && imgCache is HardDiskCache && !IsRecording)
            {
                HardDiskCache hdCache = imgCache as HardDiskCache;

                using (GifCreator gifEncoder = new GifCreator(delay))
                {
                    int i     = 0;
                    int count = hdCache.Count;

                    foreach (Image img in hdCache.GetImageEnumerator())
                    {
                        i++;
                        OnEncodingProgressChanged((int)((float)i / count * 100));

                        using (img)
                        {
                            gifEncoder.AddFrame(img, quality);
                        }
                    }

                    gifEncoder.Finish();
                    gifEncoder.Save(path);
                }
            }
        }
 private void Fetch(object sender, ElapsedEventArgs e)
 {
     try
     {
         _timer.Enabled = false;
         var jobContainer = _jobsRepository.GetJobs();
         foreach (var job in jobContainer.data)
         {
             try
             {
                 var beerPlayers = JsonConvert.DeserializeObject <List <BeerPlayer> >(job.paramaters);
                 var gifCreator  = new GifCreator(beerPlayers);
                 var result      = gifCreator.CreateGif();
                 _jobsRepository.UpdateJob(new UpdateJobDTO()
                 {
                     jobId         = job.jobid,
                     status        = 1,
                     statusMessage = result
                 });
             }
             catch (Exception ex)
             {
                 SetFailureStatus(ex.ToString(), job.jobid);
             }
         }
     }
     catch (Exception ex)
     {
     }
     finally
     {
         _timer.Enabled = true;
     }
 }
示例#3
0
 public static void CreateGif()
 {
     if (!_actionHappened && KeyboardExtended.Current.WasSingleClick(Keys.G))
     {
         _actionHappened = true;
         GifCreator.CreateGif(Globals.CurrentFolder);
     }
 }
示例#4
0
 public VideoViewModel(IEventAggregator eventAggregator, ISettings settings, IDialogBuilder dialogBuilder,
                       GifCreator gifCreator, IFileDeleter fileDeleter)
 {
     _settings      = settings;
     _dialogBuilder = dialogBuilder;
     _gifCreator    = gifCreator;
     eventAggregator.Subscribe(this);
     AddTimeline();
     fileDeleter.OnDelete(OnFileDelete);
 }
        private async void OnConvert(object sender, RoutedEventArgs e)
        {
            var gifCreator = new GifCreator();

            var picker = new FileSavePicker
            {
                SuggestedStartLocation = PickerLocationId.PicturesLibrary,
                DefaultFileExtension   = ".gif",
                SuggestedFileName      = Path.ChangeExtension(sourceFile.Name, ".gif")
            };

            var resources = ResourceLoader.GetForCurrentView();

            picker.FileTypeChoices.Add(resources.GetString("GIFImages"), new[] { ".gif" }.ToList());

            var destinationFile = await picker.PickSaveFileAsync();

            if (destinationFile != null)
            {
                ProgressBar.Value = 0.0;

                ProgressRing.IsActive  = true;
                ProgressBar.Visibility = Visibility.Visible;

                CancelButton.Visibility = Visibility.Visible;

                var videoProperties = await sourceFile.Properties.GetVideoPropertiesAsync();

                try
                {
                    _action = gifCreator.TranscodeGifAsync(sourceFile, destinationFile, videoProperties.Width,
                                                           videoProperties.Height);

                    _action.Progress = OnProgress;

                    await _action;

                    if (_action.Status == AsyncStatus.Completed)
                    {
                        await Launcher.LaunchFileAsync(destinationFile);
                    }
                }
                catch (TaskCanceledException)
                {
                }
                finally
                {
                    _action = null;

                    ProgressRing.IsActive   = false;
                    CancelButton.Visibility = Visibility.Collapsed;
                    ProgressBar.Visibility  = Visibility.Collapsed;
                }
            }
        }
示例#6
0
        private async Task TranscodeSingleFileAsync()
        {
            var firstVideo = _sourceFiles.First();

            var sourceFile = firstVideo.File;

            var gifCreator = new GifCreator();

            var picker = new FileSavePicker
            {
                SuggestedStartLocation = PickerLocationId.PicturesLibrary,
                DefaultFileExtension   = ".gif",
                SuggestedFileName      = Path.ChangeExtension(sourceFile.Name, ".gif")
            };

            var resources = ResourceLoader.GetForCurrentView();

            picker.FileTypeChoices.Add(resources.GetString("GIFImages"), new[] { ".gif" }.ToList());

            var destinationFile = await picker.PickSaveFileAsync();

            if (destinationFile != null)
            {
                Initialize();

                var videoProperties = await sourceFile.Properties.GetVideoPropertiesAsync();

                try
                {
                    _operation = gifCreator.TranscodeGifAsync(sourceFile, destinationFile, firstVideo.Width,
                                                              firstVideo.Height, firstVideo.FrameRate);

                    _operation.Progress = OnProgress;

                    var succeeded = await _operation;

                    if (succeeded && _operation.Status == AsyncStatus.Completed)
                    {
                        await Launcher.LaunchFileAsync(destinationFile);
                    }
                }
                catch (TaskCanceledException)
                {
                }
                finally
                {
                    Cleanup();
                }
            }
        }
示例#7
0
    private void SaveAnimatedGif()
    {
        if ((leftimage != null) && (rightimage != null))
        {
            SaveImages("anim0.bmp", "anim1.bmp");

            if ((File.Exists("anim0.bmp")) &&
                (File.Exists("anim1.bmp")))
            {
                //List<string> images = new List<string>();
                //images.Add("anim0.gif");
                //images.Add("anim1.gif");

                GifCreator.CreateFromStereoPair("anim0.bmp", "anim1.bmp", "anim.gif", 1000, stereo_camera.offset_x, stereo_camera.offset_y, stereo_camera.scale, stereo_camera.rotation * 180 / (float)Math.PI, reverse_colours);
                //File.Delete("anim0.gif");
                //File.Delete("anim1.gif");
                //MessageBox.Show("Animated gif created");
            }
        }
    }
示例#8
0
        private void saveAnimatedGifToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if ((picLeftImage.Image != null) && (picRightImage.Image != null))
            {
                picLeftImage.Image.Save("anim0.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
                picRightImage.Image.Save("anim1.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

                if ((File.Exists("anim0.bmp")) &&
                    (File.Exists("anim1.bmp")))
                {
                    //List<string> images = new List<string>();
                    //images.Add("anim0.gif");
                    //images.Add("anim1.gif");

                    GifCreator.CreateFromStereoPair("anim0.bmp", "anim1.bmp", "anim.gif", 1000, stereo_camera.offset_x, stereo_camera.offset_y, stereo_camera.scale, stereo_camera.rotation * 180 / (float)Math.PI, false);
                    //File.Delete("anim0.gif");
                    //File.Delete("anim1.gif");
                    MessageBox.Show("Animated gif created");
                }
            }
        }
示例#9
0
        private async Task TranscodeMultipleFilesAsync()
        {
            var picker = new FolderPicker
            {
                SuggestedStartLocation = PickerLocationId.PicturesLibrary,
                ViewMode = PickerViewMode.List,
            };

            picker.FileTypeFilter.Add(".gif");

            var folder = await picker.PickSingleFolderAsync();

            if (folder == null)
            {
                return;
            }

            Initialize();

            try

            {
                _operation = AsyncInfo.Run(async delegate(CancellationToken token, IProgress <double> progress)
                {
                    var progressPerFile = 100 / Convert.ToDouble(_sourceFiles.Count);

                    progress.Report(0.0);

                    var fileIndex = 0.0;

                    foreach (var item in _sourceFiles)
                    {
                        var sourceFile = item.File;

                        var desiredName = Path.ChangeExtension(item.Name, ".gif");

                        var destinationFile = await folder.CreateFileAsync(desiredName, CreationCollisionOption.GenerateUniqueName);

                        if (token.IsCancellationRequested)
                        {
                            return(false);
                        }

                        try
                        {
                            var gifCreator = new GifCreator();

                            var action = gifCreator.TranscodeGifAsync(sourceFile, destinationFile, item.Width,
                                                                      item.Height, item.FrameRate);

                            action.Progress = delegate(IAsyncOperationWithProgress <bool, double> a, double v)
                            {
                                if (token.IsCancellationRequested)
                                {
                                    action.Cancel();
                                }

                                progress.Report((fileIndex * progressPerFile) + progressPerFile * v / 100.0);
                            };

                            await action;

                            if (token.IsCancellationRequested)
                            {
                                return(false);
                            }
                        }
                        catch (System.Exception se)
                        {
                            System.Diagnostics.Debug.WriteLine(se.Message);
                        }

                        fileIndex++;
                    }

                    return(true);
                });

                _operation.Progress = OnProgress;

                await _operation;

                await Launcher.LaunchFolderAsync(folder);
            }
            catch (TaskCanceledException)
            {
            }
            finally
            {
                Cleanup();
            }
        }
        private void Update()
        {
            if ((picLeftImage.Image != null) &&
                (picRightImage.Image != null) &&
                (left_image_filename != "") &&
                (right_image_filename != ""))
            {
                picAnimation.Enabled = false;
                if (picAnimation.Image != null)
                {
                    picAnimation.Image.Dispose();
                    picAnimation.Image = null;
                }
                //System.Threading.Thread.Sleep(2000);

                if ((processed_left_image_filename != "") &&
                    (processed_left_image_filename != null))
                {
                    if (processed_left_image_filename != left_image_filename)
                    {
                        if (File.Exists(processed_left_image_filename))
                        {
                            File.Delete(processed_left_image_filename);
                            processed_left_image_filename = "";
                        }
                    }
                }
                if ((processed_right_image_filename != "") &&
                    (processed_right_image_filename != null))
                {
                    if (processed_right_image_filename != right_image_filename)
                    {
                        if (File.Exists(processed_right_image_filename))
                        {
                            File.Delete(processed_right_image_filename);
                            processed_right_image_filename = "";
                        }
                    }
                }

                if (delay_mS < 10)
                {
                    delay_mS = 10;
                }

                timAnimation.Interval = delay_mS;

                GifCreator.CreateFromStereoPair(
                    left_image_filename,
                    right_image_filename,
                    gif_filename,
                    delay_mS,
                    offset_x,
                    offset_y,
                    scale,
                    rotation_degrees,
                    reverse_colours,
                    ref processed_left_image_filename,
                    ref processed_right_image_filename);
                ResizeForm();

                picAnimation.Enabled = true;
            }
        }
示例#11
0
        //Save
        private void btn_save_Click(object sender, EventArgs e)
        {
            //Check whether the file already exist

            {
                if (new System.IO.FileInfo(path).Exists)
                {
                    string defpath = path.Substring(0, path.LastIndexOf('.'));
                    int    counter = 2;
                    string ext     = path.Substring(path.LastIndexOf('.'));
                    path = defpath + " (" + counter.ToString() + ")" + ext;

                    while ((new System.IO.FileInfo(path)).Exists)
                    {
                        counter += 1;
                        path     = path.Substring(0, path.Length - 7) + "(" + counter.ToString() + ")" + ext;
                    }


                    //Info
                    string msg = "A file with the name \"" + defpath + ext + "\" does already exist. Do you want to rename the file into \"" + path + "\"?";

                    if ((MessageBox.Show(msg, "File already exists", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != System.Windows.Forms.DialogResult.Yes))
                    {
                        return;
                    }
                }


                Bitmap bmp;

                //Save the current gen
                bool[,] currgen = Attributes.Cells;

                //Save
                switch (safetype)
                {
                case SafeTypes.Bitmap:

                    bmp = new Bitmap(AFieldOfLife.Width, AFieldOfLife.Height);
                    Attributes.Cells = Attributes.CurrentCellStack.ToArray()[Attributes.CurrentCellStack.Count - 1 - gen];

                    AFieldOfLife.DrawOnGfx(Graphics.FromImage(bmp));
                    bmp.Save(path);

                    break;

                case SafeTypes.GIF:

                    List <Bitmap> bmplist = new List <Bitmap>();
                    foreach (bool[,] generation in Attributes.CurrentCellStack)
                    {
                        Attributes.Cells = generation;
                        bmp = new Bitmap(AFieldOfLife.Width, AFieldOfLife.Height);
                        AFieldOfLife.DrawOnGfx(Graphics.FromImage(bmp));

                        //to get longer intervals
                        bmplist.Add(bmp);
                        bmplist.Add(bmp);
                    }

                    GifCreator.Save(bmplist, path);

                    break;

                case SafeTypes.Data:

                    //Save the data in a textfile

                    using (System.IO.StreamWriter streamw = new System.IO.StreamWriter(new System.IO.FileStream(path, System.IO.FileMode.CreateNew), System.Text.Encoding.UTF8))
                    {
                        streamw.WriteLine(Attributes.AmountOfCellsPerLine.ToString());

                        bool[,] gentowrite = Attributes.CurrentCellStack.ToArray()[Attributes.CurrentCellStack.Count - 1 - gen];

                        for (int i = 0; i <= gentowrite.GetUpperBound(0); i++)
                        {
                            for (int j = 0; j <= gentowrite.GetUpperBound(1); j++)
                            {
                                streamw.Write(Convert.ToInt32(gentowrite[j, i]).ToString() + " ");
                            }
                            streamw.WriteLine();
                        }
                    }


                    break;
                }

                //Restore last gen
                Attributes.Cells = currgen;

                this.Close();
            }
        }