private void btnStartDisplay_Click(object sender, EventArgs e)
        {
            try
            {
                display.Width  = width;
                display.Height = height;

                image1 = new Bitmap(width, height, PixelFormat.Format24bppRgb);
                g1     = Graphics.FromImage(image1);
                //使绘图质量最高,即消除锯齿
                g1.SmoothingMode      = SmoothingMode.AntiAlias;
                g1.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                g1.CompositingQuality = CompositingQuality.HighQuality;
                g1.TextRenderingHint  = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
            }
            catch
            {
                MessageBox.Show("Wrong with input!!");
            }
            g     = new Generator(width, height);
            speed = int.Parse(tbSpeed.Text);

            if (btnSpeedSwitch.Text == "Degree")
            {
                step = g.DegreeToWidth(speed);
            }
            else
            {
                step = (int)speed;
            }


            pointSize = float.Parse(tbPointSize.Text);

            if (btnPointSizeSwitch.Text == "Degree")
            {
                pointSize = g.DegreeToWidth(pointSize);
            }
            else
            {
                pointSize = (int)pointSize;
            }
            if (pointSize < 1)
            {
                MessageBox.Show("PointSize less than 1 !!!");
            }
            this.lblPointNumber.Text     = (width / (float)pointSize).ToString();
            this.lblShowStepAverage.Text = (step / (float)pointSize).ToString();
            MessageBox.Show(((int)pointSize).ToString());
            rg = new RandomPointGenerator(width, height, (int)pointSize);

            randomRate = int.Parse(tbRandomRate.Text);

            rg.setRandomPoint(randomRate);


            timer1.Interval = 1000 / frameRate;
            timer1.Start();
        }
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            this.timer1.Stop();
            rg = new RandomPointGenerator(width, height, (int)pointSize);


            rg.setRandomPoint(randomRate);


            progressBar1.Maximum = (int)(frameRate * time);
            progressBar1.Value   = progressBar1.Minimum = 0;//设置范围最小值


            VideoFileWriter writer = new VideoFileWriter();

            writer.Open(savePath, width, height, frameRate, VideoCodec.MPEG4);

            for (int ii = 0; ii != (int)(frameRate * time); ii++)
            {
                Application.DoEvents();
                g1.Clear(Color.White);
                for (int i = 0; i != width; i++)
                {
                    for (int j = 0; j != height; j++)
                    {
                        if (rg.randomCanvasBackground[i][j] == 0)
                        {
                            image1.SetPixel(i, j, Color.Black);
                        }
                    }
                }


                if (rbLeftToRight.Checked)
                {
                    rg.MoveRightForSimpleCanvas(step);
                }
                else if (rbRightToLeft.Checked)
                {
                    rg.MoveLeftForSimpleCanvas(step);
                }
                else
                {
                    ;
                }

                writer.WriteVideoFrame(image1);


                this.progressBar1.Value = ii;
            }

            writer.Close();
            this.progressBar1.Value = (int)(frameRate * time);
            MessageBox.Show("Saved!!");
        }
Beispiel #3
0
 public RandomPointMoving(int width, int height, int pointSize, int barSize, int setRandomPoint)
 {
     this.width          = width;
     this.height         = height;
     this.pointSize      = pointSize;
     this.barSize        = barSize;
     this.setRandomPoint = setRandomPoint;
     background          = new RandomPointGenerator(width, height, pointSize);
     bar = new RandomPointGenerator(barSize, height, pointSize);
     background.setRandomPoint(setRandomPoint);
     bar.setRandomPoint(setRandomPoint);
 }