private void buttonConvert_Click(object sender, EventArgs e) { if (!converter.IsRunning) { // Add images and set the duration for every slide Slide slide; slide = converter.AddImageFromFileName("..\\..\\..\\..\\slide1.jpg"); slide.Duration = 3000; // 3000ms = 3s slide = converter.AddImageFromFileName("..\\..\\..\\..\\slide2.jpg"); slide.Duration = 3000; slide = converter.AddImageFromFileName("..\\..\\..\\..\\slide3.jpg"); slide.Duration = 3000; // Set output video size converter.OutputWidth = 400; converter.OutputHeight = 300; // Set output video file name converter.OutputVideoFileName = "result.wmv"; // Set progress notification target window converter.SetProgressNotifyWindow(Handle.ToInt32(), WM_CONVERSION_PROGRESS, 0); // Run the conversion converter.Run(); } }
private void btnCreateMovie_Click(object sender, EventArgs e) { if (!_imageToVideo.IsRunning) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "WMV files (*.wmv)|*.wmv|AVI files (*.avi)|*.avi|All files (*.*)|*.*"; if (tabControl2.SelectedIndex == 0) { dlg.DefaultExt = "*.wmv"; dlg.FilterIndex = 1; } else { dlg.DefaultExt = "*.avi"; dlg.FilterIndex = 2; } dlg.FileName = "movie"; dlg.Title = "Save generated video as"; if (String.IsNullOrEmpty(Settings.Default.LastUsedFolder2)) { Settings.Default.LastUsedFolder2 = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); } dlg.InitialDirectory = Settings.Default.LastUsedFolder2; if (dlg.ShowDialog() == DialogResult.OK) { Settings.Default.LastUsedFolder2 = Path.GetDirectoryName(dlg.FileName); int intValue; float floatValue; _imageToVideo.AutoFitImages = cbAutoFitImages.Checked; _imageToVideo.KeepAspectRatio = cbKeepAspectRatio.Checked; _imageToVideo.BackgroundColor = (uint)ColorTranslator.ToOle(btnBackgroundColor.BackColor); if (tbBackgroundImage.Text.Length > 0) { _imageToVideo.SetBackgroundPictureFileName(tbBackgroundImage.Text); } if (int.TryParse(tbMovieWidth.Text, out intValue)) { _imageToVideo.OutputWidth = intValue; } if (int.TryParse(tbMovieHeight.Text, out intValue)) { _imageToVideo.OutputHeight = intValue; } if (tbAudioTrack.Text.Length > 0) { _imageToVideo.ExternalAudioTrackFromFileName = tbAudioTrack.Text; } _imageToVideo.CurrentAudioCodec = cmbAviAudioCodecs.SelectedIndex; _imageToVideo.CurrentVideoCodec = cmbAviVideoCodecs.SelectedIndex; _imageToVideo.CurrentWMVAudioCodec = cmbWmvAudioCodecs.SelectedIndex; _imageToVideo.CurrentWMVAudioFormat = cmbWmvAudioFormats.SelectedIndex; _imageToVideo.CurrentWMVVideoCodec = cmbWmvVideoCodecs.SelectedIndex; if (int.TryParse(tbBitrate.Text, out intValue)) { _imageToVideo.WMVVideoBitrate = intValue * 1024; } if (float.TryParse(tbFPS.Text, out floatValue)) { _imageToVideo.FPS = floatValue; } _outputFile = dlg.FileName; _imageToVideo.OutputVideoFileName = _outputFile; _imageToVideo.SetProgressNotifyWindow(Handle.ToInt32(), WM_CONVERSION_PROGRESS, 0); _imageToVideo.Slides.Clear(); foreach (ListViewItem item in lvInputFiles.Items) { SlideOptions slideInfo = (SlideOptions)item.Tag; Slide slide = _imageToVideo.AddImageFromFileName(slideInfo.ImageFile); slide.Duration = slideInfo.SlideDuration; slide.RotationAngle = slideInfo.SlideRotation; slide.VisualEffect = slideInfo.VisualEffect; slide.Effect = slideInfo.VisualEffectTransition; slide.EffectDuration = slideInfo.VisualEffectDuration; slide.InEffect = slideInfo.RandomTransitionEffectBefore ? GetRandomEffect() : slideInfo.TransitionEffectBefore; slide.InEffectDuration = slideInfo.TransitionEffectBeforeDuration; slide.OutEffect = slideInfo.RandomTransitionEffectAfter ? GetRandomEffect() : slideInfo.TransitionEffectAfter; slide.OutEffectDuration = slideInfo.TransitionEffectAfterDuration; } _imageToVideo.Run(); toolStripStatusLabel1.Text = "Generating video..."; btnCreateMovie.Text = "Stop"; btnCreateMovie.Image = Resources.stop; } } else { // Stop generation _imageToVideo.Stop(); // wait a bit the converter finished and released resources while (_imageToVideo.IsRunning) { Thread.Sleep(200); } toolStripStatusLabel1.Text = "Interrupted by user."; btnCreateMovie.Text = "Create Movie"; btnCreateMovie.Image = Resources.film; toolStripProgressBar1.Value = 0; } }