public static Bitmap SetColorFilter(Bitmap sourceBmap, ColorFilterTypes colorFilterType)
        {
            Bitmap bmap = sourceBmap.Clone() as Bitmap;

            DateTime startTime = DateTime.Now;

            Color c;

            for (int i = 0; i < bmap.Width; i++)
            {
                for (int j = 0; j < bmap.Height; j++)
                {
                    c = bmap.GetPixel(i, j);
                    int nPixelR = 0;
                    int nPixelG = 0;
                    int nPixelB = 0;
                    if (colorFilterType == ColorFilterTypes.Red)
                    {
                        nPixelR = c.R;
                        nPixelG = c.G - 255;
                        nPixelB = c.B - 255;
                    }
                    else if (colorFilterType == ColorFilterTypes.Green)
                    {
                        nPixelR = c.R - 255;
                        nPixelG = c.G;
                        nPixelB = c.B - 255;
                    }
                    else if (colorFilterType == ColorFilterTypes.Blue)
                    {
                        nPixelR = c.R - 255;
                        nPixelG = c.G - 255;
                        nPixelB = c.B;
                    }
                    nPixelR = Math.Max(nPixelR, 0);
                    nPixelR = Math.Min(255, nPixelR);

                    nPixelG = Math.Max(nPixelG, 0);
                    nPixelG = Math.Min(255, nPixelG);

                    nPixelB = Math.Max(nPixelB, 0);
                    nPixelB = Math.Min(255, nPixelB);

                    bmap.SetPixel(i, j, Color.FromArgb((byte)nPixelR,
                                                       (byte)nPixelG, (byte)nPixelB));
                }
            }

            DateTime endTime = DateTime.Now;

            Console.WriteLine("Elapsed: {0} milliseconds", endTime.Subtract(startTime).TotalMilliseconds);

            return(bmap);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bmp"></param>
        /// <param name="colorFilterType"></param>
        /// <returns></returns>
        /// <see cref="http://www.codeproject.com/KB/GDI-plus/ImageProcessing2.aspx"/>
        public static Bitmap SetColorFilter(this Bitmap bmp, ColorFilterTypes colorFilterType)
        {
            Debug.Assert(bmp != null);
            using (bmp)
            {
                Bitmap clone = (Bitmap)bmp.Clone();

                for (int i = 0; i < clone.Width; i++)
                {
                    for (int j = 0; j < clone.Height; j++)
                    {
                        Color c = clone.GetPixel(i, j);

                        int nPixelR = 0;
                        int nPixelG = 0;
                        int nPixelB = 0;

                        if (colorFilterType == ColorFilterTypes.Red)
                        {
                            nPixelR = c.R;
                            nPixelG = c.G - 255;
                            nPixelB = c.B - 255;
                        }
                        else if (colorFilterType == ColorFilterTypes.Green)
                        {
                            nPixelR = c.R - 255;
                            nPixelG = c.G;
                            nPixelB = c.B - 255;
                        }
                        else if (colorFilterType == ColorFilterTypes.Blue)
                        {
                            nPixelR = c.R - 255;
                            nPixelG = c.G - 255;
                            nPixelB = c.B;
                        }

                        nPixelR = Math.Max(nPixelR, 0);
                        nPixelR = Math.Min(255, nPixelR);

                        nPixelG = Math.Max(nPixelG, 0);
                        nPixelG = Math.Min(255, nPixelG);

                        nPixelB = Math.Max(nPixelB, 0);
                        nPixelB = Math.Min(255, nPixelB);

                        clone.SetPixel(i, j, Color.FromArgb((byte)nPixelR, (byte)nPixelG, (byte)nPixelB));
                    }
                }
                return(clone);
            }
        }
Example #3
0
        public static Image <Rgba32> SetColorFilter(Image <Rgba32> image, ColorFilterTypes colorFilterType)
        {
            Image <Rgba32> bmap = (Image <Rgba32>)image.Clone();
            Rgba32         c;

            for (int i = 0; i < bmap.Width; i++)
            {
                for (int j = 0; j < bmap.Height; j++)
                {
                    c = bmap[i, j];
                    int nPixelR = 0;
                    int nPixelG = 0;
                    int nPixelB = 0;
                    if (colorFilterType == ColorFilterTypes.Red)
                    {
                        nPixelR = c.R;
                        nPixelG = c.G - 255;
                        nPixelB = c.B - 255;
                    }
                    else if (colorFilterType == ColorFilterTypes.Green)
                    {
                        nPixelR = c.R - 255;
                        nPixelG = c.G;
                        nPixelB = c.B - 255;
                    }
                    else if (colorFilterType == ColorFilterTypes.Blue)
                    {
                        nPixelR = c.R - 255;
                        nPixelG = c.G - 255;
                        nPixelB = c.B;
                    }
                    else
                    {
                        return(SetGrayscale(bmap));
                    }

                    nPixelR = Math.Max(nPixelR, 0);
                    nPixelR = Math.Min(255, nPixelR);

                    nPixelG = Math.Max(nPixelG, 0);
                    nPixelG = Math.Min(255, nPixelG);

                    nPixelB = Math.Max(nPixelB, 0);
                    nPixelB = Math.Min(255, nPixelB);

                    bmap[i, j] = new Rgba32((byte)nPixelR, (byte)nPixelG, (byte)nPixelB);
                }
            }
            return((Image <Rgba32>)bmap.Clone());
        }
Example #4
0
        public static Bitmap SetColorFilter(Bitmap image, ColorFilterTypes colorFilterType)
        {
            Bitmap bmap = (Bitmap)image.Clone();
            Color  c;

            for (int i = 0; i < bmap.Width; i++)
            {
                for (int j = 0; j < bmap.Height; j++)
                {
                    c = bmap.GetPixel(i, j);
                    int nPixelR = 0;
                    int nPixelG = 0;
                    int nPixelB = 0;
                    if (colorFilterType == ColorFilterTypes.Red)
                    {
                        nPixelR = c.R;
                        nPixelG = c.G - 255;
                        nPixelB = c.B - 255;
                    }
                    else if (colorFilterType == ColorFilterTypes.Green)
                    {
                        nPixelR = c.R - 255;
                        nPixelG = c.G;
                        nPixelB = c.B - 255;
                    }
                    else if (colorFilterType == ColorFilterTypes.Blue)
                    {
                        nPixelR = c.R - 255;
                        nPixelG = c.G - 255;
                        nPixelB = c.B;
                    }
                    else
                    {
                        return(SetGrayscale(bmap));
                    }

                    nPixelR = Math.Max(nPixelR, 0);
                    nPixelR = Math.Min(255, nPixelR);

                    nPixelG = Math.Max(nPixelG, 0);
                    nPixelG = Math.Min(255, nPixelG);

                    nPixelB = Math.Max(nPixelB, 0);
                    nPixelB = Math.Min(255, nPixelB);

                    bmap.SetPixel(i, j, Color.FromArgb((byte)nPixelR, (byte)nPixelG, (byte)nPixelB));
                }
            }
            return((Bitmap)bmap.Clone());
        }
Example #5
0
        public void SetColorFilter(ColorFilterTypes colorFilterType)
        {
            Bitmap temp = (Bitmap)_currentBitmap;
            Bitmap bmap = (Bitmap)temp.Clone();
            Color  c;

            for (int i = 0; i < bmap.Width; i++)
            {
                for (int j = 0; j < bmap.Height; j++)
                {
                    c = bmap.GetPixel(i, j);
                    int nPixelR = 0;
                    int nPixelG = 0;
                    int nPixelB = 0;
                    if (colorFilterType == ColorFilterTypes.Red)
                    {
                        nPixelR = c.R;
                        nPixelG = c.G - 255;
                        nPixelB = c.B - 255;
                    }
                    else if (colorFilterType == ColorFilterTypes.Green)
                    {
                        nPixelR = c.R - 255;
                        nPixelG = c.G;
                        nPixelB = c.B - 255;
                    }
                    else if (colorFilterType == ColorFilterTypes.Blue)
                    {
                        nPixelR = c.R - 255;
                        nPixelG = c.G - 255;
                        nPixelB = c.B;
                    }

                    nPixelR = Math.Max(nPixelR, 0);
                    nPixelR = Math.Min(255, nPixelR);

                    nPixelG = Math.Max(nPixelG, 0);
                    nPixelG = Math.Min(255, nPixelG);

                    nPixelB = Math.Max(nPixelB, 0);
                    nPixelB = Math.Min(255, nPixelB);

                    bmap.SetPixel(i, j, Color.FromArgb((byte)nPixelR, (byte)nPixelG, (byte)nPixelB));
                }
                //Progress Bar
            }
            _currentBitmap = (Bitmap)bmap.Clone();
        }
Example #6
0
        public static Bitmap SetColorFilter(Bitmap image, ColorFilterTypes colorFilterType)
        {
            Bitmap bmap = (Bitmap)image.Clone();
            Color c;
            for (int i = 0; i < bmap.Width; i++)
            {
                for (int j = 0; j < bmap.Height; j++)
                {
                    c = bmap.GetPixel(i, j);
                    int nPixelR = 0;
                    int nPixelG = 0;
                    int nPixelB = 0;
                    if (colorFilterType == ColorFilterTypes.Red)
                    {
                        nPixelR = c.R;
                        nPixelG = c.G - 255;
                        nPixelB = c.B - 255;
                    }
                    else if (colorFilterType == ColorFilterTypes.Green)
                    {
                        nPixelR = c.R - 255;
                        nPixelG = c.G;
                        nPixelB = c.B - 255;
                    }
                    else if (colorFilterType == ColorFilterTypes.Blue)
                    {
                        nPixelR = c.R - 255;
                        nPixelG = c.G - 255;
                        nPixelB = c.B;
                    }
                    else
                        return SetGrayscale(bmap);

                    nPixelR = Math.Max(nPixelR, 0);
                    nPixelR = Math.Min(255, nPixelR);

                    nPixelG = Math.Max(nPixelG, 0);
                    nPixelG = Math.Min(255, nPixelG);

                    nPixelB = Math.Max(nPixelB, 0);
                    nPixelB = Math.Min(255, nPixelB);

                    bmap.SetPixel(i, j, Color.FromArgb((byte)nPixelR, (byte)nPixelG, (byte)nPixelB));
                }
            }
            return (Bitmap)bmap.Clone();
        }
Example #7
0
        public void SetColorFilter(ColorFilterTypes colorFilterType)
        {
            Bitmap temp = (Bitmap)_imagemBMP;
            Bitmap bmap = (Bitmap)temp.Clone();
            Color  c;

            for (int i = 0; i < bmap.Width; i++)
            {
                for (int j = 0; j < bmap.Height; j++)
                {
                    c = bmap.GetPixel(i, j);
                    int nPixelR = 0;
                    int nPixelG = 0;
                    int nPixelB = 0;
                    if (colorFilterType == ColorFilterTypes.Vermelho)
                    {
                        nPixelR = c.R;
                        nPixelG = c.G - 255;
                        nPixelB = c.B - 255;
                    }
                    else if (colorFilterType == ColorFilterTypes.Verde)
                    {
                        nPixelR = c.R - 255;
                        nPixelG = c.G;
                        nPixelB = c.B - 255;
                    }
                    else if (colorFilterType == ColorFilterTypes.Azul)
                    {
                        nPixelR = c.R - 255;
                        nPixelG = c.G - 255;
                        nPixelB = c.B;
                    }

                    nPixelR = Math.Max(nPixelR, 0);
                    nPixelR = Math.Min(255, nPixelR);

                    nPixelG = Math.Max(nPixelG, 0);
                    nPixelG = Math.Min(255, nPixelG);

                    nPixelB = Math.Max(nPixelB, 0);
                    nPixelB = Math.Min(255, nPixelB);

                    bmap.SetPixel(i, j, Color.FromArgb((byte)nPixelR, (byte)nPixelG, (byte)nPixelB));
                }
            }
            _imagemBMP = (Bitmap)bmap.Clone();
        }
Example #8
0
        public void SetColorFilter(ColorFilterTypes colorFilterType)
        {
            Bitmap bitmap2 = (Bitmap)this.bitmap_0.Clone();

            for (int i = 0; i < bitmap2.Width; i++)
            {
                for (int j = 0; j < bitmap2.Height; j++)
                {
                    Color pixel = bitmap2.GetPixel(i, j);
                    int   r     = 0;
                    int   g     = 0;
                    int   b     = 0;
                    if (colorFilterType == ColorFilterTypes.Red)
                    {
                        r = pixel.R;
                        g = pixel.G - 0xff;
                        b = pixel.B - 0xff;
                    }
                    else if (colorFilterType == ColorFilterTypes.Green)
                    {
                        r = pixel.R - 0xff;
                        g = pixel.G;
                        b = pixel.B - 0xff;
                    }
                    else if (colorFilterType == ColorFilterTypes.Blue)
                    {
                        r = pixel.R - 0xff;
                        g = pixel.G - 0xff;
                        b = pixel.B;
                    }
                    r = Math.Max(r, 0);
                    r = Math.Min(0xff, r);
                    g = Math.Max(g, 0);
                    g = Math.Min(0xff, g);
                    b = Math.Max(b, 0);
                    b = Math.Min(0xff, b);
                    bitmap2.SetPixel(i, j, Color.FromArgb((byte)r, (byte)g, (byte)b));
                }
            }
            this.bitmap_0 = (Bitmap)bitmap2.Clone();
        }
        public void SetColorFilter(ColorFilterTypes colorFilterType)
        {
            imageHandler.RestorePrevious();
            ColorMatrix cMatrix = new ColorMatrix(CurrentColorMatrix.Array);

            switch (colorFilterType)
            {
            case ColorFilterTypes.Red:
                cMatrix.Matrix11 = 0;
                cMatrix.Matrix22 = 0;
                break;

            case ColorFilterTypes.Green:
                cMatrix.Matrix00 = 0;
                cMatrix.Matrix22 = 0;
                break;

            case ColorFilterTypes.Blue:
                cMatrix.Matrix00 = 0;
                cMatrix.Matrix11 = 0;
                break;
            }
            imageHandler.ProcessBitmap(cMatrix);
        }
Example #10
0
        public void SetColorFilter(ColorFilterTypes colorFilterType)
        {
            Bitmap temp = (Bitmap)_currentBitmap;
            Bitmap bmap = (Bitmap)temp.Clone();
            Color c;
            for (int i = 0; i < bmap.Width; i++)
            {
                for (int j = 0; j < bmap.Height; j++)
                {
                    c = bmap.GetPixel(i, j);
                    int nPixelR = 0;
                    int nPixelG = 0;
                    int nPixelB = 0;
                    if (colorFilterType == ColorFilterTypes.Red)
                    {
                        nPixelR = c.R;
                        nPixelG = c.G - 255;
                        nPixelB = c.B - 255;
                    }
                    else if (colorFilterType == ColorFilterTypes.Green)
                    {
                        nPixelR = c.R - 255;
                        nPixelG = c.G;
                        nPixelB = c.B - 255;
                    }
                    else if (colorFilterType == ColorFilterTypes.Blue)
                    {
                        nPixelR = c.R - 255;
                        nPixelG = c.G - 255;
                        nPixelB = c.B;
                    }

                    nPixelR = Math.Max(nPixelR, 0);
                    nPixelR = Math.Min(255, nPixelR);

                    nPixelG = Math.Max(nPixelG, 0);
                    nPixelG = Math.Min(255, nPixelG);

                    nPixelB = Math.Max(nPixelB, 0);
                    nPixelB = Math.Min(255, nPixelB);

                    bmap.SetPixel(i, j, Color.FromArgb((byte)nPixelR, (byte)nPixelG, (byte)nPixelB));
                }
            }
            _currentBitmap = (Bitmap)bmap.Clone();
        }
Example #11
0
        public void SetColorFilter(ColorFilterTypes colorFilterType)
        {
            Bitmap temp = this.currentBitmap;
            Bitmap bmap = (Bitmap)temp.Clone();
            for (int i = 0; i < bmap.Width; i++)
            {
                for (int j = 0; j < bmap.Height; j++)
                {
                    Color c = bmap.GetPixel(i, j);
                    var nPixelR = 0;
                    var nPixelG = 0;
                    var nPixelB = 0;
                    switch (colorFilterType)
                    {
                        case ColorFilterTypes.Red:
                            nPixelR = c.R;
                            nPixelG = c.G - 255;
                            nPixelB = c.B - 255;
                            break;
                        case ColorFilterTypes.Green:
                            nPixelR = c.R - 255;
                            nPixelG = c.G;
                            nPixelB = c.B - 255;
                            break;
                        case ColorFilterTypes.Blue:
                            nPixelR = c.R - 255;
                            nPixelG = c.G - 255;
                            nPixelB = c.B;
                            break;
                    }
                    nPixelR = Math.Max(nPixelR, 0);
                    nPixelR = Math.Min(255, nPixelR);

                    nPixelG = Math.Max(nPixelG, 0);
                    nPixelG = Math.Min(255, nPixelG);

                    nPixelB = Math.Max(nPixelB, 0);
                    nPixelB = Math.Min(255, nPixelB);

                    bmap.SetPixel(i, j, Color.FromArgb((byte)nPixelR, (byte)nPixelG, (byte)nPixelB));
                }
            }
            this.currentBitmap = (Bitmap)bmap.Clone();
        }
Example #12
0
 public ColorFilter(XmlElement act)
 {
     this.filter = Parsing.ParseEnum<ColorFilterTypes>(act, "filter");
 }