Exemple #1
0
        private void OnEventImage()
        {
            try
            {
                if (bmp_ != null)
                {
                    if (this.tabControl1.SelectedIndex != 0)
                    {
                        return;
                    }
                    uint nWidth = 0, nHeight = 0;
                    if (radioButton2.Checked)
                    {
                        byte[,,] arr = new byte[bmp_.Height, bmp_.Width, 3];
                        IntPtr pointer = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0);

                        toupcam_.PullImage(pointer, 24, out nWidth, out nHeight);
                        int x = trackBar4.Value;
                        int y = trackBar5.Value;
                        int w = int.Parse(comboBox2.Text);
                        int h = int.Parse(comboBox3.Text);;
                        //Marshal.Copy(pointer, arr2, 0, arr.Length);
                        for (int i = y; i < h + y; i++)
                        {
                            arr[i, x, 1]         = 255;
                            arr[i, x + 1, 1]     = 255;
                            arr[i, x + 2, 1]     = 255;
                            arr[i, x + w, 1]     = 255;
                            arr[i, x + w - 1, 1] = 255;
                            arr[i, x + w - 2, 1] = 255;
                        }
                        for (int j = x; j < w + x; j++)
                        {
                            arr[y, j, 1]         = 255;
                            arr[y + 1, j, 1]     = 255;
                            arr[y + 2, j, 1]     = 255;
                            arr[y + h, j, 1]     = 255;
                            arr[y + h - 1, j, 1] = 255;
                            arr[y + h - 2, j, 1] = 255;
                        }
                        pictureBox1.Image = new Bitmap((int)nWidth, (int)nHeight, (int)nWidth * 3, PixelFormat.Format24bppRgb,
                                                       Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0));
                        pictureBox1.Update();
                        label5.Text = Math.Round(fPSCounter.Count(), 2).ToString();
                        label5.Update();
                    }
                    else if (radioButton1.Checked)
                    {
                        if (checkBox4.Checked)
                        {
                            byte[,,] arr1 = new byte[bmp_.Height, bmp_.Width, 3];
                            IntPtr pointer = Marshal.UnsafeAddrOfPinnedArrayElement(arr1, 0);
                            toupcam_.PullImage(pointer, 24, out nWidth, out nHeight);

                            int x = trackBar4.Value;
                            int y = trackBar5.Value;
                            int w = int.Parse(comboBox2.Text);
                            int h = int.Parse(comboBox3.Text);;

                            byte[,,] arr = new byte[h, w, 3];

                            for (int i = y; i < h + y; i++)
                            {
                                for (int j = x; j < w + x; j++)
                                {
                                    arr[i - y, j - x, 0] = arr1[i, j, 0];
                                    arr[i - y, j - x, 1] = arr1[i, j, 1];
                                    arr[i - y, j - x, 2] = arr1[i, j, 2];
                                }
                            }
                            //if (checkBox2.Checked)
                            //{
                            calculator.PutImage(arr,
                                                level: (int)numericUpDown2.Value,
                                                unwrap: checkBox3.Checked,
                                                wavelength: settings.wavelength,
                                                smooth: checkBox5.Checked,
                                                summDepth: checkBox6.Checked ? (int)numericUpDown1.Value : 0,
                                                calc: checkBox2.Checked,
                                                delTrend: checkBox7.Checked);

                            var buff = calculator.GetImage();
                            if (buff != null)
                            {
                                hpi2 = buff;
                            }
                            if (hpi2 != null)
                            {
                                arr = hpi2._images[0];
                                pictureBox1.Image = new Bitmap((int)w, (int)h, (int)w * 3, PixelFormat.Format24bppRgb,
                                                               Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0));
                                pictureBox1.Update();
                                label5.Text = Math.Round(fPSCounter.Count(), 2).ToString();
                                label5.Update();
                            }
                            //}
                            //else
                            //{
                            //    pictureBox1.Image = new Bitmap((int)w, (int)h, (int)w * 3, PixelFormat.Format24bppRgb,
                            //        Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0));
                            //    pictureBox1.Update();
                            //    label5.Text = Math.Round(fPSCounter.Count(), 2).ToString();
                            //    label5.Update();
                            //}
                        }
                        else
                        {
                            byte[,,] arr1 = new byte[bmp_.Height, bmp_.Width, 3];
                            IntPtr pointer = Marshal.UnsafeAddrOfPinnedArrayElement(arr1, 0);
                            toupcam_.PullImage(pointer, 24, out nWidth, out nHeight);
                            pictureBox1.Image = new Bitmap(bmp_.Width, bmp_.Height, bmp_.Width * 3, PixelFormat.Format24bppRgb,
                                                           Marshal.UnsafeAddrOfPinnedArrayElement(arr1, 0));
                            pictureBox1.Update();
                            label5.Text = Math.Round(fPSCounter.Count(), 2).ToString();
                            label5.Update();
                        }
                    }


                    //button4_Click(null, null);
                }
            }
            catch { }
        }