Example #1
0
        private void openButton_Click(object sender, RoutedEventArgs e)
        {
            InfoStackPanel.Children.RemoveRange(0, InfoStackPanel.Children.Count);
            char[]   delimiter = { ',' };
            string[] fileNames = filesTextBox.Text.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
            if (fileNames.Length <= 0)
            {
                return;
            }
            openButton.IsEnabled     = false;
            progressBar.Value        = 0;
            progressBar.Minimum      = 0;
            progressBar.Maximum      = fileNames.Length;
            progressPanel.Visibility = Visibility.Visible;
            textBlocks       = new TextBlock[fileNames.Length];
            brightnessValues = new int[fileNames.Length];
            bitmaps          = new BitmapSource[fileNames.Length];

            Thread gelThread = new Thread(new ThreadStart(delegate {
                for (int i = 0; i < fileNames.Length; ++i)
                {
                    BitmapFrame frame = BitmapFrame.Create(new Uri(fileNames[i]));
                    bitmaps[i]        = ImageUtility.ToGrayScale(frame);
                    Gel.IsInGel(ImageUtility.ToArrayImage(bitmaps[i]),
                                (int)frame.PixelWidth, (int)frame.PixelHeight,
                                configWindow.StartRow, configWindow.EndRow,
                                ref brightnessValues[i],
                                configWindow.NumOfSidePixcel,
                                configWindow.BrightnessThreshold,
                                configWindow.BinarizeThreshold,
                                configWindow.PowerOfDiffrence);
                    Dispatcher.BeginInvoke(new Action(delegate {
                        progressBar.Value     = i;
                        progressLabel.Content = string.Format(
                            "{0}/{1}", i.ToString(), fileNames.Length);
                    }), null);
                }
                Dispatcher.BeginInvoke(new Action(gelThreadCallback), null);
            }));

            gelThread.IsBackground = true;
            gelThread.Start();
        }