Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
        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;
        }