Пример #1
0
        public Bitmap ApplyFilter(Bitmap image, IFilterParameters filterParameters)
        {
            matrixFilterParameters = filterParameters as MatrixFilterParameters;
            if (matrixFilterParameters == null)
            {
                throw new ArgumentException();
            }

            var destImage = new Bitmap(image);

            resultImage = new LockBitmap(destImage);
            resultImage.LockBits();

            sourceImage = new LockBitmap(image);
            sourceImage.LockBits();

            matrixLength = Convert.ToInt32(Math.Sqrt(matrixFilterParameters.Matrix.Length));
            Parallel.For(0, sourceImage.Width, x =>
            {
                for (int y = 0; y < sourceImage.Height; y++)
                {
                    Wrap(x, y);
                }
            });
            resultImage.UnlockBits();
            sourceImage.UnlockBits();
            return destImage;
        }
Пример #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     IFilterParameters parameters = null;
     if (gaussianRadio.Checked)
     {
         parameters = new GausianFilterParameters
         {
             Sigma = intensityBar.Value
         };
     }
     if (contrastRadio.Checked)
     {
         parameters = new ContrastFilterParameters
         {
             Threshold = intensityBar.Value
         };
     }
     if (matrixRadio.Checked)
     {
         parameters = new MatrixFilterParameters
         {
             Divider = Convert.ToInt32(normalizationTextBox.Text),
             Matrix = GetMatrix()
         };
     }
     StartWatch();
     resultPictureBox.Image = FiltersContainer.Process(sourcePictureBox.Image as Bitmap,
         new List<IFilterParameters> { parameters });
     StopWatch();
 }