Exemplo n.º 1
0
        private void AddImageToFilm(AviReaderWriter aviWriter, Image im)
        {
            Bitmap bp = new Bitmap(im, videoSize.Width, videoSize.Height);

            bp.RotateFlip(RotateFlipType.Rotate180FlipX);
            aviWriter.AddFrame(bp);
            bp.Dispose();
        }
Exemplo n.º 2
0
        private void Generate(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.FileName = "Film.avi";
            saveFileDialog1.Filter   = "Fichier video (*.avi)|*.avi";
            if (listeEtapes.Count > 1)
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    string fichier = saveFileDialog1.FileName;
                    videoName = fichier;
                    AviReaderWriter aw = new AviReaderWriter();
                    try
                    {
                        uint   framePerSecond = 25;
                        Bitmap bmp            = aw.Open(fichier, framePerSecond, vidWidth, vidHeight);
                        // image de base
                        pBox.Image = Image.FromFile(ImPath);
                        Bitmap bp = new Bitmap(pBox.Image, vidWidth, vidHeight);
                        bp.RotateFlip(RotateFlipType.Rotate180FlipX);
                        aw.AddFrame(bp);
                        bp.Dispose();
                        Graphics gr = Graphics.FromImage(pBox.Image);
                        // calcul longueur totale du chemin
                        long      longTot = 0;
                        RouteStep s       = (RouteStep)listeEtapes[0];
                        for (int i = 1; i < listeEtapes.Count; i++)
                        {
                            RouteStep f = (RouteStep)listeEtapes[i];
                            longTot = longTot + StepLength(s, f);
                            s       = f;
                        }
                        RouteStep init = (RouteStep)listeEtapes[0];
                        Pen       p    = new Pen(init.Color, init.LineWidth);
                        for (int i = 1; i < listeEtapes.Count; i++)
                        {
                            RouteStep fin  = (RouteStep)listeEtapes[i];
                            long      wdEt = (long)(fin.Location.X - init.Location.X) * (fin.Location.X - init.Location.X);
                            long      htEt = (long)(fin.Location.Y - init.Location.Y) * (fin.Location.Y - init.Location.Y);
                            long      lgEt = (long)Math.Sqrt(wdEt + htEt) * (long)vidLength / longTot;
                            if (lgEt < 1)
                            {
                                lgEt = 5;
                            }
                            int d = (int)lgEt; // nombre d'images pour une étape
                                               //                                Trace.WriteLine(d);
                            float x     = fin.Location.X - init.Location.X;
                            float y     = fin.Location.Y - init.Location.Y;
                            float slope = y / x;
                            for (int j = 1; j <= d; j++)
                            {
                                long step  = (long)x * j / d;
                                long hstep = (long)(step * slope);
                                gr.DrawLine(p, init.Location.X, init.Location.Y, init.Location.X + step, init.Location.Y + hstep);
                                if (init.Text != "")
                                {
                                    gr.DrawString(init.Text, new Font("Times New Roman", 20), Brushes.White, new Point(init.Location.X + 2, init.Location.Y));
                                }
                                pBox.Refresh();
                                bp = new Bitmap(pBox.Image, vidWidth, vidHeight);
                                bp.RotateFlip(RotateFlipType.Rotate180FlipX);
                                aw.AddFrame(bp);
                                bp.Dispose();
                            }
                            init = fin;
                            p.Dispose();
                            p = new Pen(init.Color, init.LineWidth);
                        }
                        if (init.Text != "")
                        {
                            gr.DrawString(init.Text, init.Font, Brushes.White, new Point(init.Location.X + 2, init.Location.Y));
                        }
                        for (int uu = 0; uu < 10; uu++)
                        {
                            bp = new Bitmap(pBox.Image, vidWidth, vidHeight);
                            bp.RotateFlip(RotateFlipType.Rotate180FlipX);
                            aw.AddFrame(bp);
                        }
                        bp.Dispose();

                        //                       aw.Close();
                    }
                    catch (AviException ex)
                    {
                        MessageBox.Show("AVI Exception in: " + ex.ToString());
                        //                       aw.Close();
                    }
                    finally
                    {
                        aw.Close();
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void Record_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog
            {
                InitialDirectory = @"D:\Documents",
                FileName         = "Film.avi",
                Filter           = "Fichier video (*.avi)|*.avi"
            };

            //        if (mediaPlayer.playState == WMPLib.WMPPlayState.wmppsPlaying)
            {
                mediaPlayer.Visible = false;
                mediaPlayer.Ctlcontrols.stop();
                mediaPlayer.close();
            }
            splitContainer1.Panel2Collapsed = false;
            curImage    = Image.FromFile(ImPath);
            curShow     = (Image)curImage.Clone();
            isRecording = true;
            Refresh();
            int imageNumber = 1;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                currentFile = saveFileDialog1.FileName;
                if (listeEtapes.Count > 1)
                {
                    #region Calcul longueur totale du chemin
                    long      longTot = 0;
                    RouteStep init    = PtToScreen(listeEtapes[0]);
                    for (int i = 1; i < listeEtapes.Count; i++)
                    {
                        RouteStep end = PtToScreen(listeEtapes[i]);
                        longTot = longTot + StepLength(init, end);
                        init    = end;
                    }
                    #endregion
                    uint            framePerSecond = 25;
                    string          fichier        = saveFileDialog1.FileName;
                    AviReaderWriter aviWriter      = new AviReaderWriter();
                    try
                    {
                        aviWriter.Open(fichier, framePerSecond, videoSize.Width, videoSize.Height);
                        // image de base
                        Bitmap bp = new Bitmap(curImage, videoSize.Width, videoSize.Height);
                        bp.RotateFlip(RotateFlipType.Rotate180FlipX);
                        aviWriter.AddFrame(bp);
                        bp.Dispose();
                        Graphics gr = Graphics.FromImage(curImage);
                        init = PtToScreen(listeEtapes[0]);
                        Pen p = new Pen(init.Color, init.LineWidth);
                        for (int i = 1; i < listeEtapes.Count; i++)
                        {
                            #region One line
                            RouteStep fin = PtToScreen(listeEtapes[i]);
                            float     x   = fin.Location.X - init.Location.X;
                            float     y   = fin.Location.Y - init.Location.Y;
                            //long largeurEtape = (long)(x * x);
                            //long hauteurEtape = (long)(y * y);
                            long longEtape = (long)Math.Sqrt((long)(x * x) + (long)(y * y)) * (long)vidLength / longTot;
                            if (longEtape < 1)
                            {
                                longEtape = 5;
                            }
                            int   d     = (int)longEtape;
                            float slope = y / x;
                            for (int j = 1; j <= d; j++)
                            {
                                #region One step
                                gr = Graphics.FromImage(curImage);
                                long step  = (long)x * j / d;
                                long hstep = (long)(step * slope);
                                if (init.Text != "")
                                {
                                    gr.DrawString(init.Text, new Font("Times New Roman", 20), Brushes.White, new Point(init.Location.X + 2, init.Location.Y));
                                }
                                RouteStep place = PtToScreen(new RouteStep(new Point((int)(init.Location.X + step), (int)(init.Location.Y + hstep))));
                                gr.DrawLine(p, place.Location.X, place.Location.Y, place.Location.X + 2, place.Location.Y + 2);
                                curShow.Dispose();
                                curShow  = (Image)curImage.Clone();
                                curIcone = (Image)curShow.Clone();
                                gr       = Graphics.FromImage(curIcone);
                                DrawIcon(gr, place, 20, 20);
                                imageNumber      += 1;
                                nombreImages.Text = imageNumber.ToString() + " image";
                                if (imageNumber > 1)
                                {
                                    nombreImages.Text += "s";
                                }
                                AddImageToFilm(aviWriter, curShow);
                                AddImageToFilm(aviWriter, curIcone);
                                //curIcone.Dispose();
                                Refresh();
                                #endregion
                            }
                            init = fin;
                            p.Dispose();
                            p = new Pen(init.Color, init.LineWidth);
                            #endregion
                        }
                        if (init.Text != "")
                        {
                            gr.DrawString(init.Text, init.Font, Brushes.White, new Point(init.Location.X + 2, init.Location.Y));
                        }
                        curShow.Dispose();
                        curShow = (Image)curImage.Clone();
                        gr      = Graphics.FromImage(curShow);
                        DrawIcon(gr, init);

                        for (int uu = 0; uu < 10; uu++)
                        {
                            AddImageToFilm(aviWriter, curIcone);
                        }
                    }
                    catch (AviException ex)
                    {
                        MessageBox.Show("AVI Exception in: " + ex.ToString());
                    }
                    finally
                    {
                        aviWriter.Close();
                    }
                }
            }
            isRecording = false;
            //splitContainer1.Panel2Collapsed = true;
        }