private System.Drawing.Bitmap getSmoothedFrame(int smoothFactor) { System.Drawing.Image rawImage = _viewer.getImage(); if (smoothFactor == 1) { return((System.Drawing.Bitmap)rawImage); } System.Drawing.Image finalImage = new System.Drawing.Bitmap(rawImage.Size.Width / smoothFactor, rawImage.Size.Height / smoothFactor); using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage)) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(rawImage, 0, 0, rawImage.Size.Width / smoothFactor, rawImage.Size.Height / smoothFactor); } rawImage.Dispose(); return((System.Drawing.Bitmap)finalImage); }
public override void saveToMovie() { //save starting state & stop playback bool startPlaying = _timer.Enabled; int startFrame = _currentFrame; _timer.Enabled = false; //TODO: Disable buttons.... //CurrentFrame = 0; //_viewer.saveToJPEG(@"C:\Temp\testMovie\test1.jpg"); //System.Drawing.Image im = _viewer.getImage(); //im.Save(@"C:\Temp\testMovie\test2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); ////debug. //return; //show save dialogue MovieExportOptions dialog = new MovieExportOptions(_posFileName, _posViewControl.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 for (int i = 0; i < NumPositions; i++) { CurrentFrame = i; //change to current frame string fname = Path.Combine(outputDir, String.Format("outfile{0:d3}.jpg", i)); _viewer.saveToJPEG(fname); } break; case MovieExportOptions.SaveType.MOVIE: //save movie try { AviManager aviManager = new AviManager(dialog.OutputFileName, false); CurrentFrame = 0; //set to first frame, so we can grab it. System.Drawing.Bitmap frame = (System.Drawing.Bitmap)_viewer.getImage(); VideoStream vStream = aviManager.AddVideoStream(dialog.MovieCompress, (double)dialog.MovieFPS, frame); for (int i = 1; i < NumPositions; i++) //start from frame 1, frame 0 was added when we began { CurrentFrame = i; //change to current frame vStream.AddFrame((System.Drawing.Bitmap)_viewer.getImage()); } aviManager.Close(); //close out and save } 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 CurrentFrame = startFrame; _timer.Enabled = startPlaying; }