Example #1
0
        private void OpenPic_Button_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new()
            {
                RestoreDirectory = true,
                Filter           = "*.jpg,*.png,*.jpeg,*.bmp,*.gif|*.jpg;*.png;*.jpeg;*.bmp;*.gif|All files(*.*)|*.*"
            };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    P_PictureBox.Image = System.Drawing.Image.FromFile(openFileDialog.FileName);

                    _isFirst   = true;
                    _PCAResult = null;
                    this.ThresholdValue_Label.Text = (this.ThresholdValue_TrackBar.Value = 30).ToString();

                    Draw_PictureBox.Refresh();
                }
                catch (System.IO.FileNotFoundException)
                {
                    MessageBox.Show("          文件不存在");
                }
                catch (Exception)
                {
                    MessageBox.Show("         读取图片异常");
                }
            }

            if (null != P_PictureBox.Image)
            {
                this.OpenPic_Button.Visible  = true;
                this.Analysis_Button.Enabled = true;
                this.Analysis_Button.Visible = true;
                this.Analysis_Button.Focus();
            }
            else
            {
                this.OpenPic_Button.Visible  = true;
                this.Analysis_Button.Enabled = false;
                this.Analysis_Button.Visible = false;
            }
        }
Example #2
0
        private void Analysis_Button_Click(object sender, EventArgs e)
        {
            if (P_PictureBox.Image != null)
            {
                Stopwatch Sw = new Stopwatch();
                Sw.Start();

                _PCAResult = Lxy.Picture.PCA.Image.Analysis(P_PictureBox.Image, ColorNum_TrackBar.Value, _isFirst && true, Delta_TrackBar.Value, ThresholdValue_TrackBar.Value);
                if (_isFirst && ThresholdValue_TrackBar.Value > _PCAResult.MaxThresholdValue && null != _PCAResult.HighlightColor)
                {
                    _isFirst = false;
                    ThresholdValue_TrackBar.Value = _PCAResult.MaxThresholdValue;
                    ThresholdValue_Label.Text     = _PCAResult.MaxThresholdValue.ToString();
                }

                Sw.Stop();
                Elapsed_Label.Text = $"耗  时:   {Sw.ElapsedMilliseconds} ms";
                _pixelAmount       = P_PictureBox.Image.Width * P_PictureBox.Image.Height;

                Draw_PictureBox.Refresh();
            }
        }