Exemple #1
0
        private void Start_Click(object sender, EventArgs e)
        {
            //pictureBox2.Image = SandDiameterMeasuring.Properties.Resources.屏幕截图_1654_;
            // pictureBox2.Image.Dispose();
            // pictureBox2.Image = null;
            textBox1.Text = ("加载图片");
            OpenFileDialog file = new OpenFileDialog();

            file.InitialDirectory = ".";
            file.Filter           = "所有文件(*.*)|*.*";
            file.ShowDialog();
            if (file.FileName != string.Empty)
            {
                try
                {
                    pathname = file.FileName;   //获得文件的绝对路径
                    this.pictureBox1.Load(pathname);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            string str1 = file.FileName;

            //str1 = "'" + str1 + "'";//加单引号为符合matlab输入规范
            textBox1.Text = (str1);
            //textBox1.Text = (file.FileName);
            DiameterCalculation.Class1 c1 = new DiameterCalculation.Class1();
            //Object sandNumber;
            MWArray        a1 = c1.linktocsharp(str1);
            MWNumericArray a2 = (MWNumericArray)a1;

            textBox2.Text = a2.ToString();

            linktocsharpV3.Class1 v3c1 = new linktocsharpV3.Class1();
            //MWArray DiameterArray = v3c1.linktocsharpV3(str1);
            MWArray[] resultlist = new MWArray[2];
            resultlist = v3c1.linktocsharpV3(2, str1);                    //重要!!!m函数有多个返回值时在第一个参数里写入返回值个数,第二个参数才是输入m函数的第一个输入参数
            MWNumericArray DiameterArray = (MWNumericArray)resultlist[0]; //返回每一粒沙子的直径数组,为n行1列的二维数组
            MWNumericArray SandNumber    = (MWNumericArray)resultlist[1]; //沙尘个数

            double[,] DA = new double[(int)SandNumber, 1];                //matlab函数返回值为二维数组,因此需要用二维数组接收
            DA           = (double[, ])DiameterArray.ToArray();
            //textBox3.Text = DA[(int)a2 - 1, 0].ToString();
            //textBox3.Text = DA[(int)SandNumber - 1, 0].ToString();



            //textBox2.Text = (sandNumber.ToString);
            string pathname2;

            pathname2 = "D:\\op\\tempresult.png";  //获得文件的绝对路径
            //this.pictureBox2.Load(pathname2);//load貌似过时了?
            // this.pictureBox2.Image = Image.FromFile(pathname2);
            //    pictureBox2.Image.Dispose();
            FileStream pFileStream = new FileStream(pathname2, FileMode.Open, FileAccess.Read);

            pictureBox2.Image = Image.FromStream(pFileStream);
            pFileStream.Close();
            pFileStream.Dispose();
        }
        private void Start_Click(object sender, EventArgs e)
        {
            //pictureBox2.Image = SandDiameterMeasuring.Properties.Resources.屏幕截图_1654_;
            // pictureBox2.Image.Dispose();
            // pictureBox2.Image = null;
            textBox1.Text = ("加载图片");
            OpenFileDialog file = new OpenFileDialog();

            file.InitialDirectory = ".";
            file.Filter           = "所有文件(*.*)|*.*";
            file.ShowDialog();
            if (file.FileName != string.Empty)
            {
                try
                {
                    pathname = file.FileName;   //获得文件的绝对路径
                    this.pictureBox1.Load(pathname);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            string str1 = file.FileName;

            //str1 = "'" + str1 + "'";//加单引号为符合matlab输入规范
            textBox1.Text = (str1);
            //textBox1.Text = (file.FileName);
            DiameterCalculation.Class1 c1 = new DiameterCalculation.Class1();
            //Object sandNumber;
            MWArray        a1 = c1.linktocsharp(str1);
            MWNumericArray a2 = (MWNumericArray)a1;

            textBox2.Text = a2.ToString();

            linktocsharpV5.Class1 v5c1 = new linktocsharpV5.Class1();
            //MWArray DiameterArray = v3c1.linktocsharpV3(str1);
            MWArray[] resultlist = new MWArray[2];
            resultlist = v5c1.linktocsharpV5(4, str1);                     //重要!!!m函数有多个返回值时在第一个参数里写入返回值个数,第二个参数才是输入m函数的第一个输入参数
            MWNumericArray DiameterArray  = (MWNumericArray)resultlist[0]; //返回每一粒沙子的直径数组,为n行1列的二维数组
            MWNumericArray SandNumber     = (MWNumericArray)resultlist[1]; //沙尘个数
            MWNumericArray DiameterNumber = (MWNumericArray)resultlist[2]; //返回以50um为单位的粒径累加结果数组
            MWNumericArray xlength        = (MWNumericArray)resultlist[3]; //返回以50um为单位的粒径累加结果数组

            double[,] DA = new double[(int)SandNumber, 1];                 //matlab函数返回值为二维数组,因此需要用二维数组接收
            DA           = (double[, ])DiameterArray.ToArray();
            double[,] DN = new double[(int)xlength, 1];                    //matlab函数返回值为二维数组,因此需要用二维数组接收
            DN           = (double[, ])DiameterNumber.ToArray();
            //textBox3.Text = DA[(int)a2 - 1, 0].ToString();
            //textBox3.Text = DA[(int)SandNumber - 1, 0].ToString();

            chart1.Series.Clear();
            ChartHelper.AddSeries(chart1, "由小到大每一粒沙尘的粒径", SeriesChartType.Column, Color.Transparent, Color.Red, true);
            //   ChartHelper.AddSeries(chart1, "由小到大每一粒沙尘的粒径", SeriesChartType.Spline, Color.Red, Color.Red);
            //   ChartHelper.SetTitle(chart1, "由小到大每一粒沙尘的粒径", new Font("微软雅黑", 8), Docking.Top, Color.Black);
            ChartHelper.SetStyle(chart1, Color.Transparent, Color.Black);
            ChartHelper.SetLegend(chart1, Docking.Top, StringAlignment.Center, Color.Transparent, Color.Black);
            ChartHelper.SetXY(chart1, "", "粒径(*50um)", StringAlignment.Far, Color.Black, Color.Black, AxisArrowStyle.SharpTriangle, 0, 0);
            ChartHelper.SetMajorGrid(chart1, Color.Transparent, 20, 50);
            List <int> xData = new List <int>()
            {
            };
            int i, j;

            for (i = 1; i <= (int)SandNumber; i++)
            {
                xData.Add(i);
            }
            List <double> yData = new List <double>()
            {
            };

            for (j = 0; j <= (int)SandNumber - 1; j++)
            {
                yData.Add(DA[j, 0]);
            }
            chart1.Series[0].Points.DataBindXY(xData, yData);

            chart2.Series.Clear();
            ChartHelper.AddSeries(chart2, "该粒径范围内沙尘个数", SeriesChartType.Column, Color.Lime, Color.Blue, true);
            //      ChartHelper.AddSeries(chart2, "曲线图", SeriesChartType.Spline, Color.Red, Color.Red);
            //      ChartHelper.SetTitle(chart2, "柱状图与曲线图", new Font("微软雅黑", 12), Docking.Bottom, Color.Black);
            ChartHelper.SetStyle(chart2, Color.Transparent, Color.Black);
            ChartHelper.SetLegend(chart2, Docking.Top, StringAlignment.Center, Color.Transparent, Color.Black);
            ChartHelper.SetXY(chart2, "粒径(*50um)", "个数", StringAlignment.Far, Color.Black, Color.Black, AxisArrowStyle.SharpTriangle, 4, (int)(DN[0, 0] / 10));
            ChartHelper.SetMajorGrid(chart2, Color.Transparent, 20, 2);
            List <int> xData2 = new List <int>()
            {
            };
            int i2, j2;

            for (i2 = 1; i2 <= (int)xlength; i2++)
            {
                xData2.Add(i2);
            }
            List <double> yData2 = new List <double>()
            {
            };

            for (j2 = 0; j2 <= (int)xlength - 1; j2++)
            {
                yData2.Add(DN[j2, 0]);
            }
            chart2.Series[0].Points.DataBindXY(xData2, yData2);


            //textBox2.Text = (sandNumber.ToString);
            string pathname2;

            pathname2 = "D:\\op\\tempresult.png";  //获得文件的绝对路径
            //this.pictureBox2.Load(pathname2);//load貌似过时了?
            // this.pictureBox2.Image = Image.FromFile(pathname2);
            //    pictureBox2.Image.Dispose();
            FileStream pFileStream = new FileStream(pathname2, FileMode.Open, FileAccess.Read);

            pictureBox2.Image = Image.FromStream(pFileStream);
            pFileStream.Close();
            pFileStream.Dispose();
        }