public Bitmap ApplyFilter(Bitmap image, int noise = 60)
        {
            SepiaFilter       filter           = new SepiaFilter();
            Merger            mergeTool        = new Merger();
            BlackNWhiteFilter blackNwhite      = new BlackNWhiteFilter();
            Bitmap            sepiaImage       = mergeTool.Merge(blackNwhite.ApplyFilter(image), filter.ApplyFilter(image), 25);
            Random            TempRandom       = new Random();
            Random            WhitePixelRandom = new Random();

            for (int x = 0; x < sepiaImage.Width; ++x)
            {
                for (int y = 0; y < sepiaImage.Height; ++y)
                {
                    int whitePixel = WhitePixelRandom.Next(1, 60);
                    if (whitePixel == 5)
                    {
                        sepiaImage.SetPixel(x, y, Color.FromArgb(255, 255, 255));
                        continue;
                    }
                    Color CurrentPixel = sepiaImage.GetPixel(x, y);
                    int   R            = CurrentPixel.R + TempRandom.Next(-noise, noise + 1);
                    int   G            = CurrentPixel.G + TempRandom.Next(-noise, noise + 1);
                    int   B            = CurrentPixel.B + TempRandom.Next(-noise, noise + 1);
                    if (R > 255)
                    {
                        R = 255;
                    }
                    else if (R < 0)
                    {
                        R = 0;
                    }
                    if (G > 255)
                    {
                        G = 255;
                    }
                    else if (G < 0)
                    {
                        G = 0;
                    }
                    if (B > 255)
                    {
                        B = 255;
                    }
                    else if (B < 0)
                    {
                        B = 0;
                    }
                    Color TempValue = Color.FromArgb(R, G, B);
                    sepiaImage.SetPixel(x, y, Color.FromArgb(R, G, B));
                }
            }
            return(sepiaImage);
        }
Exemplo n.º 2
0
        public System.Drawing.Bitmap ApplyFilter(Image image, EFilter filtro, Color color = default(Color), int brightness = 0, int noise = 60,
                                                 RotateFlipType RFT = RotateFlipType.RotateNoneFlipNone)
        {
            switch (filtro)
            {
            case EFilter.AutomaticAdjustmentFilter:
                AutomaticAdjustmentFilter AAF = new AutomaticAdjustmentFilter();
                return(AAF.ApplyFilter(image.BitmapImage));

            case EFilter.BlackNWhiteFilter:
                BlackNWhiteFilter BNWF = new BlackNWhiteFilter();
                return(BNWF.ApplyFilter(image.BitmapImage));

            case EFilter.BrightnessFilter:
                BrightnessFilter BF = new BrightnessFilter();
                return(BF.ApplyFilter(image.BitmapImage, brightness));

            case EFilter.ColorFilter:
                ColorFilter CF = new ColorFilter();
                return(CF.ApplyFilter(image.BitmapImage, color));

            case EFilter.InvertFilter:
                InvertFilter IF = new InvertFilter();
                return(IF.ApplyFilter(image.BitmapImage));

            case EFilter.MirrorFilter:
                MirrorFilter MF = new MirrorFilter();
                return(MF.ApplyFilter(image.BitmapImage));

            case EFilter.OldFilmFilter:
                OldFilmFilter OFF = new OldFilmFilter();
                return(OFF.ApplyFilter(image.BitmapImage, noise));

            case EFilter.RotateFlipFilter:
                RotateFlipFilter RFF = new RotateFlipFilter();
                return(RFF.RotateFlip(image.BitmapImage, RFT));

            case EFilter.SepiaFilter:
                SepiaFilter SF = new SepiaFilter();
                return(SF.ApplyFilter(image.BitmapImage));

            case EFilter.WindowsFilter:
                WindowsFilter WF = new WindowsFilter();
                return(WF.ApplyFilter(image.BitmapImage));
            }
            return(image.BitmapImage);
        }