public void test() { DoubleAnimation anim = new DoubleAnimation(50, 400, TimeSpan.FromSeconds(10), System.Windows.Media.Animation.FillBehavior.HoldEnd); var clock = anim.CreateClock(); this.ellipse1.ApplyAnimationClock(Canvas.LeftProperty, clock); clock.Controller.Pause(); int dpi = 96; int fps = 24; int anim_length_in_secs = 5; int num_total_frames = fps * anim_length_in_secs; var secs = Enumerable.Range(0, num_total_frames).Select(t => (((double)t) / fps)); AviManager aviManager = new AviFile.AviManager(filename, false); VideoStream aviStream = null; foreach (var sec in secs) { clock.Controller.SeekAlignedToLastTick(TimeSpan.FromSeconds(sec), System.Windows.Media.Animation.TimeSeekOrigin.BeginTime); this.canvas1.UpdateLayout(); string temp_bitmap = "d:\\canvas_frame.png"; util.SaveCanvas(this, this.canvas1, dpi, temp_bitmap); System.Drawing.Bitmap bm = new System.Drawing.Bitmap(temp_bitmap); if (aviStream == null) { aviStream = aviManager.AddVideoStream(compress, fps, bm); } else { aviStream.AddFrame(bm); } bm.Dispose(); } aviManager.Close(); }
private void buttonCreateAVI_Click(object sender, EventArgs e) { this.Log("Starting"); string src_folder = this.textBoxBitmapsFolder.Text.Trim(); string out_filename = this.textBoxAVIFile.Text.Trim(); this.Log("folder = \"{0}\"", src_folder ); if (src_folder.Length<1) { this.Log("folder must enter folder"); this.LogFailure(); return; } if (! System.IO.Directory.Exists(src_folder)) { this.Log("folder does not exist"); this.LogFailure(); return; } if (System.IO.File.Exists(src_folder)) { this.Log("this is a file nor a folder"); this.LogFailure(); return; } this.Log("output file = \"{0}\"", out_filename ); if (out_filename.Length < 1) { this.Log("must enter out filename"); this.LogFailure(); return; } string [] bitmap_files = System.IO.Directory.GetFiles(src_folder, "*.png"); this.Log("Number of bitmaps = {0}", bitmap_files.Length); // WORKITEM sort the names // WORKITEM print the names? // WORKITEM warn about different sizes // WORKITEM show dimensions Bitmap bmp = (Bitmap)Image.FromFile(bitmap_files[0]); AviFile.AviManager aviManager=null; try { aviManager = new AviFile.AviManager(out_filename, false); } catch (System.Exception ex) { this.Log(ex.Message); this.Log(ex.Source); this.Log("Could not create AviManager object"); this.Log("Sometimes this means the AVI file is open in an app (like WMP). CLose any apps using it and try again."); this.LogFailure(); return; } bool compress = this.checkBoxUseCompression.Checked; this.Log("Compression setting = {0}", compress); this.Log("Creating AVIManager"); AviFile.VideoStream aviStream = aviManager.AddVideoStream( compress, 10, bmp); Bitmap bitmap; int count = 0; for (int n = 1; n < bitmap_files.Length; n++) { this.Log("Frame {0} Loading bitmap {1} ", n, bitmap_files[n]); bitmap = (Bitmap)Bitmap.FromFile(bitmap_files[n]); this.Log("Adding bitmap frame"); aviStream.AddFrame(bitmap); bitmap.Dispose(); count++; } this.Log("Closing Avi Manger"); aviManager.Close(); this.Log("Done."); }
private void OnVideotape(object obj) { //bool saveOnMotion = false; CameraCtrl.OnVideotape(obj); Func <string> createVideoFile = () => { DateTime date = DateTime.Now; String fileName = String.Format("{0}-{1}-{2} {3}-{4}-{5}.avi", date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second); return(fileName); }; //是否开始录像 if (!saveVideoMonitor) { Camera camera = MainWindow.CameraWindow.Camera; AviFile.AviManager aviManager = new AviFile.AviManager(VideoPath + createVideoFile(), false); double rate = videoRecRate == 0 ? 5.0 : videoRecRate; camera.Lock(); AviFile.VideoStream aviStream = aviManager.AddVideoStream(false, rate, camera.LastFrame); camera.Unlock(); Thread videoRecordThread; Action startVideoRecoder = () => { videoRecordThread = new Thread(() => { Camera _camera = MainWindow.CameraWindow.Camera; while (true) { try { _camera.Lock(); aviStream.AddFrame(MainWindow.CameraWindow.Camera.LastFrame); _camera.Unlock(); Thread.Sleep(500); } catch (Exception) { } } if (aviManager != null) { aviManager.Close(); } videoRecordThread.Abort(); }); videoRecordThread.IsBackground = true; videoRecordThread.Start(); }; saveVideoMonitor = true; } /* * 录像功能 */ //if (!saveOnMotion) //{ // if (dlg.ShowDialog() == DialogResult.OK) // { // Camera camera = cameraWindow.Camera; // aviManager = new AviManager(VideoPath + CreateVideoFile(), false); // double Rate = dlg.Rate == 0.0 ? videoRecRate : dlg.Rate; // camera.Lock(); // aviStream = aviManager.AddVideoStream(false, Rate, camera.LastFrame); // camera.Unlock(); // StartVideoRecorder(); // saveOnMotion = true; // } //} //else //{ // saveOnMotion = false; //} }
private void StartVideoRecord(string filename) { Thread t = new Thread(() => { var aviManager = new AviFile.AviManager(filename, false); AviFile.VideoStream stream = null; System.Drawing.Bitmap frame; while(!frames.TryDequeue(out frame)) Thread.Sleep(50); stream = aviManager.AddVideoStream(true, 30, frame); frame.Dispose(); while (frames.TryDequeue(out frame)) { stream.AddFrame(frame); frame.Dispose(); Dispatcher.BeginInvoke((Action)(() => { FramesLeftDisplay.Text = string.Format("{0} frames left", frames.Count); })); } aviManager.Close(); Dispatcher.BeginInvoke((Action)(() => { MessageBox.Show("Compression done!"); })); }); t.Start(); }
public override void saveToMovie() { //save starting state & stop playback bool startPlaying = _animationControl.AnimationTimer.Enabled; _animationControl.AnimationTimer.Stop(); //show save dialogue MovieExportOptions dialog = new MovieExportOptions(_xrommFileSys.subjectPath, _animationControl.FPS); dialog.ShowDialog(); //okay, now lets figure out what we are doing here switch (dialog.results) { case MovieExportOptions.SaveType.CANCEL: //nothing to do, we were canceled break; case MovieExportOptions.SaveType.IMAGES: //save images string outputDir = dialog.OutputFileName; //save it to a movie _viewer.cacheOffscreenRenderer(); for (int i = 0; i < _animationControl.NumberOfFrames; i++) { _fullXromm.SetToPositionAndFixedBoneAndTrial(i, _fixedBoneIndex, _currentTrialIndex); //change to current frame string fname = System.IO.Path.Combine(outputDir, String.Format("outfile{0:d3}.jpg", i)); _viewer.saveToJPEG(fname); } _viewer.clearOffscreenRenderer(); break; case MovieExportOptions.SaveType.MOVIE: //save movie try { AviFile.AviManager aviManager = new AviFile.AviManager(dialog.OutputFileName, false); int smooth = dialog.SmoothFactor; _viewer.cacheOffscreenRenderer(smooth); //TODO: Check that output is multiple of 4!!!! _fullXromm.SetToPositionAndFixedBoneAndTrial(0, _fixedBoneIndex, _currentTrialIndex);; //set to first frame, so we can grab it. System.Drawing.Bitmap frame = getSmoothedFrame(smooth); AviFile.VideoStream vStream = aviManager.AddVideoStream(dialog.MovieCompress, (double)dialog.MovieFPS, frame); for (int i = 1; i < _animationControl.NumberOfFrames; i++) //start from frame 1, frame 0 was added when we began { _fullXromm.SetToPositionAndFixedBoneAndTrial(i, _fixedBoneIndex, _currentTrialIndex); vStream.AddFrame(getSmoothedFrame(smooth)); } aviManager.Close(); //close out and save _viewer.clearOffscreenRenderer(); } catch (Exception ex) { string msg = "Error saving to movie file.\n\n" + ex.Message; libWrist.ExceptionHandling.HandledExceptionManager.ShowDialog(msg, "", "", ex); } break; } //wrap us up, resume frame and playing status _fullXromm.SetToPositionAndFixedBoneAndTrial(_animationControl.currentFrame, _fixedBoneIndex, _currentTrialIndex); if (startPlaying) { _animationControl.AnimationTimer.Start(); } }
private void buttonCreateAVI_Click(object sender, EventArgs e) { this.Log("Starting"); string src_folder = this.textBoxBitmapsFolder.Text.Trim(); string out_filename = this.textBoxAVIFile.Text.Trim(); this.Log("folder = \"{0}\"", src_folder); if (src_folder.Length < 1) { this.Log("folder must enter folder"); this.LogFailure(); return; } if (!System.IO.Directory.Exists(src_folder)) { this.Log("folder does not exist"); this.LogFailure(); return; } if (System.IO.File.Exists(src_folder)) { this.Log("this is a file nor a folder"); this.LogFailure(); return; } this.Log("output file = \"{0}\"", out_filename); if (out_filename.Length < 1) { this.Log("must enter out filename"); this.LogFailure(); return; } string [] bitmap_files = System.IO.Directory.GetFiles(src_folder, "*.png"); this.Log("Number of bitmaps = {0}", bitmap_files.Length); // WORKITEM sort the names // WORKITEM print the names? // WORKITEM warn about different sizes // WORKITEM show dimensions Bitmap bmp = (Bitmap)Image.FromFile(bitmap_files[0]); AviFile.AviManager aviManager = null; try { aviManager = new AviFile.AviManager(out_filename, false); } catch (System.Exception ex) { this.Log(ex.Message); this.Log(ex.Source); this.Log("Could not create AviManager object"); this.Log("Sometimes this means the AVI file is open in an app (like WMP). CLose any apps using it and try again."); this.LogFailure(); return; } bool compress = this.checkBoxUseCompression.Checked; this.Log("Compression setting = {0}", compress); this.Log("Creating AVIManager"); AviFile.VideoStream aviStream = aviManager.AddVideoStream(compress, 10, bmp); Bitmap bitmap; int count = 0; for (int n = 1; n < bitmap_files.Length; n++) { this.Log("Frame {0} Loading bitmap {1} ", n, bitmap_files[n]); bitmap = (Bitmap)Bitmap.FromFile(bitmap_files[n]); this.Log("Adding bitmap frame"); aviStream.AddFrame(bitmap); bitmap.Dispose(); count++; } this.Log("Closing Avi Manger"); aviManager.Close(); this.Log("Done."); }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new Form1()); try { string filename = args[0]; int dpi = 96; int fps = 24; int anim_length_in_secs = int.Parse(args[1]); int num_total_frames = fps * anim_length_in_secs; var secs = Enumerable.Range(0, num_total_frames).Select(t => (((double)t) / fps)); var aviManager = new AviFile.AviManager(filename, false); AviFile.VideoStream aviStream = null; foreach (var sec in secs) { Process[] processes = Process.GetProcessesByName("EmlakSlide.vshost"); Process lol = processes[0]; IntPtr ptr = lol.MainWindowHandle; Rect rect = new Rect(); GetWindowRect(ptr, ref rect); int width = rect.Right - rect.Left; int height = rect.Bottom - rect.Top - 57; var bmp = new Bitmap(width, height); Graphics graphics = Graphics.FromImage(bmp); graphics.CopyFromScreen(rect.Left, rect.Top + 57, 0, 0, new System.Drawing.Size(width, height), CopyPixelOperation.SourceCopy); bmp.Save("test.png", ImageFormat.Png); string temp_bitmap = "test.png"; // await ConvertToBitmapSource(canvas1); System.Drawing.Bitmap bm = new System.Drawing.Bitmap(temp_bitmap); if (aviStream == null) { aviStream = aviManager.AddVideoStream(true, fps, bm); } else { aviStream.AddFrame(bm); } bm.Dispose(); } aviManager.Close(); MessageBox.Show("video kaydedildi"); } catch (Exception e) { MessageBox.Show(e.Message); } }