Exemple #1
0
        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);
        }
Exemple #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);
        }
Exemple #3
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.AutomaticAdjustment:
                AutomaticAdjustmentFilter AAF = new AutomaticAdjustmentFilter();
                Bitmap ret = AAF.ApplyFilter(image.BitmapImage);
                GC.Collect();
                return(ret);

            case EFilter.Grayscale:
                BlackNWhiteFilter BNWF = new BlackNWhiteFilter();
                Bitmap            ret2 = BNWF.ApplyFilter(image.BitmapImage);
                GC.Collect();
                return(ret2);

            case EFilter.Brightness:
                BrightnessFilter BF   = new BrightnessFilter();
                Bitmap           ret3 = BF.ApplyFilter(image.BitmapImage, brightness);
                GC.Collect();
                return(ret3);

            case EFilter.Color:
                ColorFilter CF   = new ColorFilter();
                Bitmap      ret4 = CF.ApplyFilter(image.BitmapImage, color);
                GC.Collect();
                return(ret4);

            case EFilter.Invert:
                InvertFilter IF   = new InvertFilter();
                Bitmap       ret5 = IF.ApplyFilter(image.BitmapImage);
                GC.Collect();
                return(ret5);

            case EFilter.Mirror:
                MirrorFilter MF   = new MirrorFilter();
                Bitmap       ret6 = MF.ApplyFilter(image.BitmapImage);
                GC.Collect();
                return(ret6);

            case EFilter.OldFilm:
                OldFilmFilter OFF  = new OldFilmFilter();
                Bitmap        ret7 = OFF.ApplyFilter(image.BitmapImage, noise);
                GC.Collect();
                return(ret7);

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

            case EFilter.Sepia:
                SepiaFilter SF   = new SepiaFilter();
                Bitmap      ret9 = SF.ApplyFilter(image.BitmapImage);
                GC.Collect();
                return(ret9);

            case EFilter.Windows:
                WindowsFilter WF    = new WindowsFilter();
                Bitmap        ret10 = WF.ApplyFilter(image.BitmapImage);
                GC.Collect();
                return(ret10);
            }
            return(image.BitmapImage);
        }