private void ApplyFilter(bool preview)
        {
            if (previewBitmap == null || cmbFilterSize.SelectedIndex == -1)
            {
                return;
            }

            Bitmap selectedSource = null;
            Bitmap bitmapResult   = null;

            if (preview == true)
            {
                selectedSource = previewBitmap;
            }
            else
            {
                selectedSource = originalBitmap;
            }

            if (selectedSource != null)
            {
                if (cmbFilterSize.SelectedItem.ToString() == "None")
                {
                    bitmapResult = selectedSource;
                }
                else
                {
                    int filterSize = 0;

                    ExtBitmap.MorphologyEdgeType edgeType = ((ExtBitmap.MorphologyEdgeType)cmbEdgeOptions.SelectedItem);
                    int    a = cmbFilterSize.SelectedItem.ToString().Length;
                    String s = cmbFilterSize.SelectedItem.ToString().Replace("System.Windows.Controls.ComboBoxItem:", "");



                    if (Int32.TryParse(s, out filterSize))


                    {
                        if (rdDilate.IsChecked == true)
                        {
                            bitmapResult = selectedSource.DilateAndErodeFilter(filterSize, ExtBitmap.MorphologyType.Dilation, (bool)chkB.IsChecked, (bool)chkG.IsChecked, (bool)chkR.IsChecked, edgeType);
                        }
                        else if (rdErode.IsChecked == true)
                        {
                            bitmapResult = selectedSource.DilateAndErodeFilter(filterSize, ExtBitmap.MorphologyType.Erosion, (bool)chkB.IsChecked, (bool)chkG.IsChecked, (bool)chkR.IsChecked, edgeType);
                        }
                        else if (rdOpen.IsChecked == true)
                        {
                            bitmapResult = selectedSource.OpenMorphologyFilter(filterSize, (bool)chkB.IsChecked, (bool)chkG.IsChecked, (bool)chkR.IsChecked);
                        }
                        else if (rdClose.IsChecked == true)
                        {
                            bitmapResult = selectedSource.CloseMorphologyFilter(filterSize, (bool)chkB.IsChecked, (bool)chkG.IsChecked, (bool)chkR.IsChecked);
                        }
                    }
                }
            }

            if (bitmapResult != null)
            {
                if (preview == true)
                {
                    ImgResult.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmapResult.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());;
                }
                else
                {
                    resultBitmap = bitmapResult;
                }
            }
        }
Esempio n. 2
0
        private void ApplyFilter(bool preview)
        {
            if (previewBitmap == null || cmbFilterSize.SelectedIndex == -1)
            {
                return;
            }

            Bitmap selectedSource = null;
            Bitmap bitmapResult   = null;

            if (preview == true)
            {
                selectedSource = previewBitmap;
            }
            else
            {
                selectedSource = originalBitmap;
            }

            if (selectedSource != null)
            {
                if (cmbFilterSize.SelectedItem.ToString() == "None")
                {
                    bitmapResult = selectedSource;
                }
                else
                {
                    int filterSize = 0;

                    ExtBitmap.MorphologyEdgeType edgeType = ((ExtBitmap.MorphologyEdgeType)cmbEdgeOptions.SelectedItem);

                    if (Int32.TryParse(cmbFilterSize.SelectedItem.ToString(), out filterSize))
                    {
                        if (rdDilate.Checked == true)
                        {
                            bitmapResult = selectedSource.DilateAndErodeFilter(filterSize, ExtBitmap.MorphologyType.Dilation, chkB.Checked, chkG.Checked, chkR.Checked, edgeType);
                        }
                        else if (rdErode.Checked == true)
                        {
                            bitmapResult = selectedSource.DilateAndErodeFilter(filterSize, ExtBitmap.MorphologyType.Erosion, chkB.Checked, chkG.Checked, chkR.Checked, edgeType);
                        }
                        else if (rdOpen.Checked == true)
                        {
                            bitmapResult = selectedSource.OpenMorphologyFilter(filterSize, chkB.Checked, chkG.Checked, chkR.Checked);
                        }
                        else if (rdClosed.Checked == true)
                        {
                            bitmapResult = selectedSource.CloseMorphologyFilter(filterSize, chkB.Checked, chkG.Checked, chkR.Checked);
                        }
                    }
                }
            }

            if (bitmapResult != null)
            {
                if (preview == true)
                {
                    picPreview.Image = bitmapResult;
                }
                else
                {
                    resultBitmap = bitmapResult;
                }
            }
        }