Example #1
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (recording)
     {
         aviWriter.Close();
         recordBtn.Text   = "Start Recording";
         recording        = false;
         statusTxt.Text   = "Stopped.";
         contBtn.Enabled  = false;
         pauseBtn.Enabled = false;
     }
     else
     {
         SaveFileDialog sfd = new SaveFileDialog();
         sfd.Filter = "Audio Video Interleave File | *.avi";
         DialogResult result = sfd.ShowDialog();
         if (result == DialogResult.OK)
         {
             statusTxt.Text = "Recording...";
             aviWriter.Close();
             String file = sfd.FileName;
             aviWriter.Open(file, pictureBox1.Size.Width, pictureBox1.Size.Height);
             recordBtn.Text   = "Stop Recording";
             recording        = true;
             paused           = false;
             pauseBtn.Enabled = true;
         }
     }
 }
        private void GrabarVideo()
        {
            AVIWriter grabadorVideo = new AVIWriter();

            try
            {
                Bitmap   imagen       = Camaras.CapturarImagen(visorCamara1);
                DateTime Hoy          = DateTime.Now;
                string   fecha_actual = Hoy.ToString("dd-MM-yyyy HH-mm-ss");
                grabadorVideo.Open(rutaCapturas + "\\video_" + fecha_actual + ".avi", imagen.Width, imagen.Height);
                while (true)
                {
                    if (grabandoVideo1)
                    {
                        grabadorVideo.AddFrame(Camaras.CapturarImagen(visorCamara1));
                        Thread.Sleep(50);
                    }
                    else
                    {
                        break;
                    }
                }
                grabadorVideo.Close();
            }
            catch (Exception)
            {
                grabadorVideo.Close();
            }
        }
Example #3
0
 private void aviSaveAs()
 {
     try
     {
         OleDbConnection conn = bc.GetConn();
         conn.Open();
         OleDbCommand cmd = new OleDbCommand("select strPath from tb_VideoPath where ID=1", conn);
         string       str = cmd.ExecuteScalar().ToString().Trim();
         FileInfo     fi  = new FileInfo(str);
         if (fi.Exists)
         {
             fi.Delete();
         }
         conn.Close();
         aviWriter = new AVIWriter();
         //avi中所有图像皆不能小于width及height
         avi_frame = aviWriter.Create(str, 1, SWidth, SHeight);
         for (int i = 0; i < al.Count; i++)
         {
             //获得图像
             Bitmap cache = new Bitmap(Image.FromFile(al[i].ToString()));
             //由于转化为avi后呈现相反,所以翻转
             cache.RotateFlip(RotateFlipType.Rotate180FlipX);
             //载入图像
             aviWriter.LoadFrame(cache);
             aviWriter.AddFrame();
         }
         aviWriter.Close();
         avi_frame.Dispose();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void recordVideo()
        {
            AVIWriter writer = new AVIWriter("wmv3");

            writer.Open("test.avi", 320, 240);
            Bitmap image = new Bitmap(320, 240);

            for (int i = 0; i < 240; i = i + 5)
            {
                if (i == 235)
                {
                    break;
                }
                if (i > 4)
                {
                    image.SetPixel(i - 1, i - 1, Color.Black);
                    image.SetPixel(i - 2, i - 2, Color.Black);
                    image.SetPixel(i - 3, i - 3, Color.Black);
                    image.SetPixel(i - 4, i - 4, Color.Black);
                    image.SetPixel(i - 5, i - 5, Color.Black);
                }

                image.SetPixel(i, i, Color.Red);
                image.SetPixel(i + 1, i + 1, Color.Red);
                image.SetPixel(i + 2, i + 2, Color.Red);
                image.SetPixel(i + 3, i + 3, Color.Red);
                image.SetPixel(i + 4, i + 4, Color.Red);

                writer.AddFrame(image);
            }
            writer.Close();
        }
Example #5
0
 public void stopSave()
 {
     saveMode = false;
     if (aviWriter != null)
     {
         aviWriter.Close();
     }
     if (frameWriter != null)
     {
         if (writeFramePosList != null && toCompress)
         {  // need to save frame positions and postion of start of frame positions
             //Int32 pos = (Int32)frameWriter.BaseStream.Position;
             foreach (Int32 fp in writeFramePosList)
             {
                 frameWriter.Write(fp);
             }
             frameWriter.Write(writePos);  // which is also the end of the last frame
         }
         frameWriter.Close();
         ((IDisposable)frameWriter).Dispose();
         frameWriter = null;
     }
     framePosList = writeFramePosList;
     fileName     = writeFileName;
 }
Example #6
0
        //call back for timer which is used to display
        //alarm window on motion detection. The timer
        //interval is 1 sec, and alarmInterval is increased
        //by n sec by alarm callback
        void timer_Tick(object sender, EventArgs e)
        {
            if (alarmInterval > 0)
            {
                alarmInterval--;
            }
            if (alarmInterval == 0)
            {
                audioPlayed        = false;
                frameDropThreshold = 0;

                if (recording)
                {
                    if (videoWriter != null)
                    {
                        try
                        {
                            Log.info(String.Format("Closing idle writer for camera {0}", options.Name));
                            videoWriter.Close();
                            videoWriter = null;
                        }
                        catch (Exception io)
                        {
                            Log.warn(String.Format("Error closing recorded video file for {0}. Record Folder: {1}. Message: {2}", options.Name, options.RecordFolder, io.Message));
                        }
                    }
                    recording = false;
                }
            }
        }
Example #7
0
        private void RecordButton_Click(object sender, EventArgs e)
        {
            if (!recordVideo)
            {
                SaveFileDialog dialog = new SaveFileDialog();

                dialog.Filter           = "Plik AVI (*.avi)|*.avi";
                dialog.FilterIndex      = 1;
                dialog.RestoreDirectory = true;
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    writer           = new AVIWriter("cvid");
                    writer.FrameRate = 5;
                    var width  = videoSource.VideoResolution.FrameSize.Width;
                    var height = videoSource.VideoResolution.FrameSize.Height;

                    writer.Open(dialog.FileName, width, height);
                    recordVideo       = true;
                    RecordButton.Name = "Stop recording";
                }
            }
            else
            {
                recordVideo = false;
                captureThread.Join();
                writer.Close();
                RecordButton.Name = "Recording";
            }
        }
 private void btn_detener_Click(object sender, EventArgs e)
 {
     if (FuenteDeVideo.IsRunning)
     {
         Termina_FuenteDeVideo();
         writer.Close();
         pcb_video.Image = Properties.Resources.offline;
         //timer1.Stop();
         timer2.Stop();
         lblServicio.Text         = "";
         lblGrabar.Text           = "";
         cmb_dispositivos.Enabled = true;
         btn_detener.Enabled      = false;
         btn_iniciar.Enabled      = true;
     }
 }
Example #9
0
 private void btnStartStopVideo_Click(object sender, EventArgs e)
 {
     if (lbCameras.SelectedIndex < 0)
     {
         MessageBox.Show("当前没有选择相机,请先选择一个相机!");
         return;
     }
     if (videoStream.IsRunning)
     {
         videoStream.Stop();
         videoWriter.Close();    // 保存视频文件
         File.Move("_video_saved\\recording.avi",
                   string.Format("_video_saved\\{0}-{1}.avi",
                                 curCamera.ToString(),
                                 DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss")));
         curCamera = null;
         timerGetData.Stop();   // 关闭同时关闭计时器
         pbCameraView.Image          = global::Monitor.Properties.Resources.no_video;
         btnStartStopVideo.Text      = "显示视频";
         btnStartStopVideo.BackColor = Color.LightGreen;
         labelVideoInfo.Text         = "请先在左侧选择相机,然后点击“显示视频”";
     }
     else
     {
         curCamera          = cameras[lbCameras.SelectedIndex];
         videoStream.Source = string.Format(videoUrlFormatter, curCamera.ip, curCamera.port);
         videoStream.Start();
         videoWriter.Open("_video_saved\\recording.avi", 352, 288); // 创建视频文件
         timerGetData.Start();                                      // 启动同时开始计时器
         btnStartStopVideo.Text      = "关闭视频";
         btnStartStopVideo.BackColor = Color.LightCoral;
         labelVideoInfo.Text         = curCamera.ToFullString();
     }
 }
Example #10
0
 public void CloseCurrent()
 {
     lock (aviWatchDog)
     {
         currentAvi.Close();
     }
 }
Example #11
0
        private void makeVideo(object _param)
        {
            isNowVideoSaving = true;
            photoThreadsCounter++;

            VideoParameters param = (VideoParameters)_param;

            Accord.Video.VFW.AVIWriter wr;
            wr = new AVIWriter();

            wr.FrameRate = Convert.ToInt32(param.FPS);
            wr.Open(param.path, 2 * param.halfWidth, 2 * param.halfHeight);

            int frameCount = param.movie.frameCount();

            for (int i = 0; i < frameCount; i++)
            {
                wr.AddFrame(param.movie[i].getFrame(param.halfWidth, param.halfHeight, grid));
                Console.WriteLine("Frame {0} out of {1} is done!", i + 1, frameCount);
                statusFrames = String.Format("{0}/{1}", i + 1, frameCount);
            }

            wr.Close();

            photoThreadsCounter--;
            isNowVideoSaving = false;
            statusFrames     = "";
        }
Example #12
0
        private void SaveAnimationButton_Click(object sender, EventArgs e)
        {
            if (bitmaps.Count == 0)
            {
                MessageBox.Show(StringResources.NoFrame);
                return;
            }
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.DefaultExt   = "avi";
            sfd.AddExtension = true;
            sfd.Filter       = "(*.avi)|*.avi";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                AVIWriter aw = new AVIWriter("MSVC");
                aw.FrameRate = Settings.framerate;
                aw.Open(sfd.FileName, FrameWidth, FrameHeight);
                for (int j = 0; j < bitmaps.Count; j++)
                {
                    Bitmap bitmap = (Bitmap)bitmaps[j].Clone();
                    double secs   = FrameDurations[j];
                    for (int i = 0; i < secs * Settings.framerate; i++)
                    {
                        aw.AddFrame(bitmap);
                    }
                }
                aw.Quality = 1;
                aw.Close();
            }
        }
Example #13
0
 public void Dispose()
 {
     if (writer_ != null)
     {
         writer_.Close();
         writer_.Dispose();
         writer_ = null;
     }
 }
Example #14
0
        //private void jpgToAVIByFFpeg(String[] pic, String newPic, int delayTime)
        //{
        //    int frameRate = 25;

        //    if (delayTime > 0)
        //        frameRate = Convert.ToInt32(1000f / delayTime);

        //    VideoFileWriter writer = new VideoFileWriter();


        //    Image im;
        //    if (tVLeft.Nodes.Count > 0)
        //    {
        //        im = Image.FromFile(tVLeft.Nodes[0].Name.ToString());
        //        int w = im.Width;
        //        int h = im.Height;
        //        progressBar1.Maximum = tVLeft.Nodes.Count;
        //        if (w % 2 != 0)
        //            w += 1;
        //        if (h % 2 != 0)
        //            h += 1;

        //        writer.Open(newPic, w, h, frameRate, VideoCodec.MPEG4);

        //        for (int i = 0; i < tVLeft.Nodes.Count; i++)
        //        {
        //            im.Dispose();
        //            im = Image.FromFile(tVLeft.Nodes[i].Name.ToString());
        //            im = BitmapToBlowUp(im, w, h);

        //            this.pictureBox1.Image = im;
        //            this.pictureBox1.Refresh();
        //            if ((im.Height != h) | (im.Width != w))
        //                MessageBox.Show(tVLeft.Nodes[i].Name.ToString() + " 文件大小与首张不符!");
        //            writer.WriteVideoFrame((Bitmap)im);

        //            progressBar1.Value += 1;

        //            curFile.Text = i.ToString() + ">>> " + getFileNameOnly(pic[i]);
        //            curFile.Refresh();
        //        }
        //        writer.Close();
        //        writer.Dispose();

        //        MessageBox.Show("AVI 动画文件转换完毕!");
        //    }
        //} // FFPEG 类生成AVI,使用 MPG4 格式压缩
        // 如果使用 FFPEG 类,则需要:
        // 1、引用如下类库:
        //  AForge.Video.FFMPEG
        // 2、将如下类库 Copy 到目标程度所在文件夹,如 bin\debug 等。
        // AForge.Net FrameWork \Externals\FFMPEG\BIN文件夹下的所有 DLL 文件
        // avcodec-53.dll,avdevice-53.dll,avfilter-2.dll,avformat-53.dll,avutil-51.dll,postproc-52.dll,swresample-0.dll,swscale-2.dll
        private void jpgToAVI(String[] pic, String newPic, int delayTime)
        {
            int frameRate = 25;

            if (delayTime > 0)
            {
                frameRate = Convert.ToInt32(1000f / delayTime);
            }

            AVIWriter aviWriter = new AVIWriter("wmv3");

            aviWriter.FrameRate = frameRate;

            Image im;

            if (tVLeft.Nodes.Count > 0)
            {
                im = Image.FromFile(tVLeft.Nodes[0].Name.ToString());
                int w = im.Width;
                int h = im.Height;
                progressBar1.Maximum = tVLeft.Nodes.Count;

                if (w % 2 != 0)
                {
                    w += 1;
                }
                if (h % 2 != 0)
                {
                    h += 1;
                }

                aviWriter.Open(newPic, w, h);  // 输出到指定的文件

                for (int i = 0; i < tVLeft.Nodes.Count; i++)
                {
                    im.Dispose();
                    im = Image.FromFile(tVLeft.Nodes[i].Name.ToString());
                    im = BitmapToBlowUp(im, w, h);

                    this.pictureBox1.Image = im;
                    this.pictureBox1.Refresh();
                    if ((im.Height != h) | (im.Width != w))
                    {
                        MessageBox.Show(tVLeft.Nodes[i].Name.ToString() + " 文件大小与首张不符!");
                    }
                    aviWriter.AddFrame((Bitmap)im);
                    progressBar1.Value += 1;

                    curFile.Text = i.ToString() + ">>> " + getFileNameOnly(pic[i]);
                    curFile.Refresh();
                }
                aviWriter.Close();
                aviWriter.Dispose();
                MessageBox.Show("AVI 动画文件转换完毕!");
            }
        } // WMV3 格式压缩
Example #15
0
        private void Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            _writer.Close();
            CloseVideoSource();

            if (ShimmerDevice1 != null)
            {
                if (ShimmerDevice1.GetState() == (int)Shimmer.SHIMMER_STATE_STREAMING)
                {
                    ShimmerDevice1.StopStreaming();
                }
                ShimmerDevice1.Disconnect();
            }

            if (ShimmerDevice2 != null)
            {
                if (ShimmerDevice2.GetState() == (int)Shimmer.SHIMMER_STATE_STREAMING)
                {
                    ShimmerDevice2.StopStreaming();
                }
                ShimmerDevice2.Disconnect();
            }

            if (_writeToFileShimmer1 != null)
            {
                _writeToFileShimmer1.CloseFile();
            }

            if (_writeToFileShimmer2 != null)
            {
                _writeToFileShimmer2.CloseFile();
            }

            buttonStreamShimmer1.Enabled = false;
            buttonStopShimmer1.Enabled   = false;
            RemoveAllTextBox("Shimmer1");
            labelPRR.Visible = false;

            buttonStreamShimmer2.Enabled = false;
            buttonStopShimmer2.Enabled   = false;
            RemoveAllTextBox("Shimmer2");
            labelPRR.Visible = false;
        }
 private void button1_Click(object sender, EventArgs e)
 {
     if (this.toggleButton.Text == "Start Rec.")
     {
         this.toggleButton.Text      = "STOP Rec.";
         this.toggleButton.BackColor = Color.Black;
         toggleButton.ForeColor      = Color.White;
         saveVideo           = new AVIWriter("wmv3");
         saveVideo.FrameRate = 15;
         saveVideo.Open("video.avi", 640, 480);
     }
     else
     {
         this.toggleButton.Text = "Start Rec.";
         toggleButton.ForeColor = Color.Black;
         toggleButton.BackColor = Color.White;
         saveVideo.Close();
     }
 }
Example #17
0
 private void button6_Click(object sender, EventArgs e)
 {
     try
     {
         writer.Close();
         MessageBox.Show("video recorded successfully");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #18
0
 public void Dispose()
 {
     if (videoStream != null)
     {
         videoStream.Close();
         videoStream.Dispose();
     }
     else
     {
         videoWriter.Close();
         videoWriter.Dispose();
     }
 }
Example #19
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (source.IsRunning == true)
     {
         source.Stop();
         videoSourcePlayer1.Stop();
     }
     if (cam != null)
     {
         cam.Stop();
         writer.Close();
     }
 }
Example #20
0
        private void btnRecord_Click(object sender, EventArgs e)
        {
            AVIWriter writer = new AVIWriter("wmv3");

            writer.Open("test.avi", 320, 240);
            Bitmap image = new Bitmap(320, 240);

            for (int i = 0; i < 240; i++)
            {
                image.SetPixel(i, i, Color.Red);
                writer.AddFrame(image);
            }
            writer.Close();
        }
Example #21
0
        private void btnParar_Click(object sender, EventArgs e)
        {
            if (videoSourcePlayer1.IsRunning)
            {
                videoSourcePlayer1.SignalToStop();
            }

            if (estaGrabando)
            {
                writer.Close();
                estaGrabando = false;
                videoSourcePlayer1.Stop();
            }
        }
Example #22
0
 void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
 {
     currentFrame = (Bitmap)eventArgs.Frame.Clone();
     if ((captureThread == null || !captureThread.IsAlive) && recordVideo)
     {
         writer.Open("test.avi", 320, 240);
         Bitmap threadFrame = (Bitmap)currentFrame.Clone();
         for (int i = 0; i < 240; i++)
         {
             writer.AddFrame(threadFrame);
         }
         writer.Close();
     }
     pictureBox1.Invoke(new Action(delegate { pictureBox1.Image = currentFrame; }));
 }
Example #23
0
 private void CleanupGeneration()
 {
     videoWriter.Close();
     IsGenerating           = false;
     replay.AllFramesReady -= ReplayAllFramesReady;
     replay.Stop();
     replay.Dispose();
     replay = null;
     //write xml to disk
     xmlwriter.write();
     System.Console.WriteLine("lastframenumber = " + lastframenumber);
     System.Console.WriteLine("framecounter = " + framecounter);
     System.Console.WriteLine("missingFrameCount = " + missingFrameCount);
     //lastframenumber
     generationstatus.Content = "Generation finished";
 }
Example #24
0
        static void Main(string[] args)
        {
            foreach (FilterInfo videoDevice in new FilterInfoCollection(FilterCategory.VideoInputDevice))
            {
                Console.WriteLine(videoDevice.Name);
            }

            FilterInfo codec = null;

            foreach (FilterInfo videoDevice in new FilterInfoCollection(FilterCategory.VideoCompressorCategory))
            {
                codec = videoDevice;
                Console.WriteLine(videoDevice.Name);
            }

            // instantiate AVI writer, use WMV3 codec
            AVIWriter writer = new AVIWriter(codec.MonikerString);

            // create new AVI file and open it
            writer.Open("test.avi", 320, 240);
            // create frame image
            Bitmap image = new Bitmap(320, 240);

            int j = 1;

            for (int i = 0; i < 240; i++)
            {
                // update image
                image.SetPixel(i, i, Color.Red);
                // add the image as a new frame of video file
                writer.AddFrame(image);

                j = j == 1 ? -1 : 1;
            }

            //Bitmap bitmap = Image.FromFile("Files/grab.mjpeg");
            //writer.AddFrame(bitmap);



            writer.Close();
        }
Example #25
0
        public void ClosePrepared()
        {
            lock (aviWatchDog)
            {
                preparedAvi.Close();
                try
                {
                    if (IsDonePrepare())
                    {
                        return;
                    }

                    if (File.Exists(PreparedFileName))
                    {
                        File.Delete(PreparedFileName);
                    }
                }
                catch { }
            }
        }
Example #26
0
 //关闭录制
 public void RecordClose()
 {
     Thread.Sleep(500);   // 防止在关闭时,aviWriter.AddFrame(lastFrame);报错
     aviWriter.Close();
     aviWriter.Dispose();
 }
Example #27
0
        private void Rendering()
        {
            //if (RecordingType == 0)
            //{
            //    int width = 750;
            //    int height = 750;
            //    DateTime time = System.DateTime.Now;
            //    //create instance of video writer
            //    VideoFileWriter writer = new VideoFileWriter();
            //    //create new video file
            //    writer.Open("Recording/vedio/" + time.Year + "-" + time.Month + "-" + time.Day
            //        + " " + time.Hour + "." + time.Minute + "." + time.Second
            //        + ".avi", width, height, 96, VideoCodec.MPEG4);
            //    //create a bitmap to save into the video file
            //    int now = liTime[0];
            //    int liTimePosition = 0;
            //    for (int i = 0; i < liTime[liTime.Count - 1]; i++)
            //    {
            //        if (i > now)
            //        {
            //            liTimePosition++;
            //            now = liTime[liTimePosition];
            //        }
            //        System.Drawing.Bitmap image = new System.Drawing.Bitmap(AppDomain.CurrentDomain.BaseDirectory + "\\Recording\\Temp\\" + (liTimePosition + 1) + ".png");
            //        writer.WriteVideoFrame(image);
            //    }
            //    //DirectoryInfo TheFolder = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\Recording\\Temp");
            //    //foreach (FileInfo NextFile in TheFolder.GetFiles())
            //    //{
            //    //    int nIndex = NextFile.Name.LastIndexOf('.');
            //    //    String filename = NextFile.Name;
            //    //    if (nIndex >= 0)
            //    //    {
            //    //        filename = filename.Substring(nIndex);
            //    //        if (filename.Equals(".png"))
            //    //        {
            //    //            System.Drawing.Bitmap image = new System.Drawing.Bitmap(AppDomain.CurrentDomain.BaseDirectory + "\\Recording\\Temp\\" + NextFile.Name);
            //    //            //NextFile.Name
            //    //            writer.WriteVideoFrame(image);
            //    //        }
            //    //    }
            //    //}
            //    writer.Close();
            //}

            DateTime time = System.DateTime.Now;
            //org.loon.util.FileUtil file = new org.loon.util.FileUtil();
            AVIWriter aviWriter = new AVIWriter();

            //ps:avi中所有图像皆不能小于width及height
            System.Drawing.Bitmap avi_frame = aviWriter.Create(AppDomain.CurrentDomain.BaseDirectory + "/Recording/vedio/" + time.Year + "-" + time.Month + "-" + time.Day
                                                               + " " + time.Hour + "." + time.Minute + "." + time.Second
                                                               + ".avi", 96, 750, 750);
            int now            = liTime[0];
            int liTimePosition = 0;

            for (int i = 0; i < liTime[liTime.Count - 1]; i++)
            {
                if (i > now)
                {
                    liTimePosition++;
                    now = liTime[liTimePosition];
                }
                //获得图像
                System.Drawing.Bitmap image = new System.Drawing.Bitmap(AppDomain.CurrentDomain.BaseDirectory + "\\Recording\\Temp\\" + (liTimePosition + 1) + ".png");

                //由于转化为avi后呈现相反,所以翻转
                image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipX);
                //载入图像
                aviWriter.LoadFrame(image);
                aviWriter.AddFrame();
            }

            //释放资源
            aviWriter.Close();
            avi_frame.Dispose();
        }
Example #28
0
 public void Stop()
 {
     //mStream.SignalToStop();
     mAviWriter.Close();
 }
Example #29
0
        public override void create_animation(string output_title, bool enable_console_output, bool using_full_path, bool allow_overwrite, bool use_floating_color_scale, DistributionSketchSettings S)
        {
            string absolute_video_output_path = video_default_repo + "\\" + output_title + ".avi";

            if (using_full_path)
            {
                absolute_video_output_path = output_title;
            }
            if (File.Exists(absolute_video_output_path) && !allow_overwrite)
            {
                throw new Exception("Error: File exists and overwrite permission not granted.");
            }
            Directory.CreateDirectory(AbsoluteDataSetLocation + "\\images");
            string[]      allfiles      = Directory.GetFiles(absolute_set_location);
            List <string> distrib_files = new List <string>();
            int           q             = 0;

            foreach (string i in allfiles)
            {
                if (i.EndsWith(".dist"))
                {
                    distrib_files.Add(i);
                    NCGrid_Distribution n = NCGrid_Distribution.from_file(i, true);
                    NCGrid_Distribution following_grid = new NCGrid_Distribution(n.Bounds, n.Xcount, n.Ycount);
                    int border = 1;
                    for (int ii = border; ii < following_grid.Xcount - border; ii++)
                    {
                        for (int jj = border; jj < following_grid.Ycount - border; jj++)
                        {
                            double   deltax  = (n.Xmax - n.Xmin) / (n.Xcount - 1);
                            double   deltay  = (n.Ymax - n.Ymin) / (n.Ycount - 1);
                            double[] stencil =
                            {
                                n[ii - 1, jj - 1].Value,
                                n[ii,     jj - 1].Value,
                                n[ii + 1, jj - 1].Value,
                                n[ii - 1, jj].Value,
                                n[ii,     jj].Value,
                                n[ii + 1, jj].Value,
                                n[ii - 1, jj + 1].Value,
                                n[ii,     jj + 1].Value,
                                n[ii + 1, jj + 1].Value,
                            };
                            double  ux   = (stencil[5] - stencil[3]) / (2 * deltax);
                            double  uy   = (stencil[7] - stencil[1]) / (2 * deltay);
                            double  uxx  = (stencil[5] + stencil[3] - (2 * stencil[4])) / (deltax * deltax);
                            double  uyy  = (stencil[7] + stencil[1] - (2 * stencil[4])) / (deltay * deltay);
                            double  uxy  = (stencil[8] + stencil[0] - stencil[6] - stencil[2]) / (4 * deltax * deltay);
                            double  dx   = 0.06 * ((uxx * ux) + (uxy * uy));
                            double  dy   = 0.06 * ((uyy * uy) + (ux * uxy));
                            Vector3 move = new Vector3(dx, dy, 0);
                            while ((following_grid[ii, jj] + move).X > n.Bounds.Xmax || (following_grid[ii, jj] + move).X <n.Bounds.Xmin || (following_grid[ii, jj] + move).Y> n.Bounds.Ymax || (following_grid[ii, jj] + move).Y < n.Bounds.Ymin)
                            {
                                dx   = 0.5 * dx;
                                dy   = 0.5 * dy;
                                move = new Vector3(dx, dy, 0);
                            }
                            following_grid[ii, jj] = following_grid[ii, jj] + move;
                        }
                    }
                    HybridDistributionSketch2D sk = new HybridDistributionSketch2D(n, S);
                    if (!use_floating_color_scale)
                    {
                        sk.override_colormap_limits(info);
                    }
                    sk.set_superimposed_grid(following_grid);
                    sk.CreateSketch(true);
                    sk.SaveImage(AbsoluteDataSetLocation + "\\images\\render" + bufferint(q++, 5) + ".bmp", true);
                }
            }
            AVIWriter V = new AVIWriter("wmv3");

            string[]      filenames = Directory.GetFiles(AbsoluteDataSetLocation + "\\images");
            List <string> bmpnames  = new List <string>();

            foreach (string i in filenames)
            {
                if (i.EndsWith(".bmp"))
                {
                    bmpnames.Add(i);
                }
            }
            if (bmpnames.Count != 0)
            {
                Bitmap first = (Bitmap)Bitmap.FromFile(bmpnames[0]);
                V.Open(absolute_video_output_path, first.Width, first.Height);
                V.FrameRate = 50;
                V.AddFrame(first);
                int ct = bmpnames.Count;
                for (int i = 1; i < bmpnames.Count; i++)
                {
                    Bitmap butt = (Bitmap)Bitmap.FromFile(bmpnames[i]);
                    if (enable_console_output)
                    {
                        Console.WriteLine(i.ToString() + " of " + ct.ToString() + " frames stacked" + "(" + (i * 100 / ct).ToString() + "%)");
                    }
                    V.AddFrame(butt);
                    butt.Dispose();
                }
                V.Close();
                first.Dispose();
                if (enable_console_output)
                {
                    Console.WriteLine("AVI successfully created on " + DateTime.Now.ToString() + " in directory " + absolute_video_output_path);
                }
                string[] imagenames = Directory.GetFiles(AbsoluteDataSetLocation + "\\images");
                foreach (string g in imagenames)
                {
                    File.Delete(g);
                }
                Directory.Delete(AbsoluteDataSetLocation + "\\images");
            }
            else
            {
                Console.WriteLine("No bitmap images found in the current directory.");
            }
        }
Example #30
0
 public void CloseWriter()
 {
     InsertRemaining();
     writer.Close();
 }