Ejemplo n.º 1
0
 private void comboBoxFilter_SelectedIndexChanged(object sender, EventArgs e)
 {
     currentFilter          = filters[comboBoxFilter.SelectedIndex];
     richTextBoxFilter.Text = currentFilter.ToString();
 }
Ejemplo n.º 2
0
        private Bitmap highFrequenceFilter(Bitmap originalBitmap, ImageFilter filter)
        {
            Bitmap newBitmap = new Bitmap(originalBitmap.Width, originalBitmap.Height);

            LockBitmap original = new LockBitmap(originalBitmap);
            LockBitmap filtered = new LockBitmap(newBitmap);

            int width  = originalBitmap.Width;
            int height = originalBitmap.Height;

            original.LockBits();
            filtered.LockBits();

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int[] result = new int[3];

                    if (y > 0 && x > 0)
                    {
                        SumArrays(result, GetPixelWithMultiply(original, x - 1, y - 1, filter.Matrix[0, 0]));
                    }
                    if (y > 0)
                    {
                        SumArrays(result, GetPixelWithMultiply(original, x, y - 1, filter.Matrix[0, 1]));
                    }
                    if (y > 0 && x < width - 1)
                    {
                        SumArrays(result, GetPixelWithMultiply(original, x + 1, y - 1, filter.Matrix[0, 2]));
                    }
                    if (x > 0)
                    {
                        SumArrays(result, GetPixelWithMultiply(original, x - 1, y, filter.Matrix[1, 0]));
                    }

                    SumArrays(result, GetPixelWithMultiply(original, x, y, filter.Matrix[1, 1]));

                    if (x < width - 1)
                    {
                        SumArrays(result, GetPixelWithMultiply(original, x + 1, y, filter.Matrix[1, 2]));
                    }
                    if (y < height - 1 && x > 0)
                    {
                        SumArrays(result, GetPixelWithMultiply(original, x - 1, y + 1, filter.Matrix[2, 0]));
                    }
                    if (y < height - 1)
                    {
                        SumArrays(result, GetPixelWithMultiply(original, x, y + 1, filter.Matrix[2, 1]));
                    }
                    if (y < height - 1 && x < width - 1)
                    {
                        SumArrays(result, GetPixelWithMultiply(original, x + 1, y + 1, filter.Matrix[2, 2]));
                    }

                    for (int i = 0; i < 3; i++)
                    {
                        if (result[i] < 0)
                        {
                            result[i] = 0;
                        }
                        if (result[i] > 255)
                        {
                            result[i] = 255;
                        }
                    }

                    filtered.SetPixel(x, y, Color.FromArgb(result[0], result[1], result[2]));
                }
            }

            filtered.UnlockBits();
            original.UnlockBits();

            return(newBitmap);
        }