Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var            processor          = new ImageProcessor();
            var            filters            = new ImageFilters();
            Action <Image> imageFilterHandler = filters.ApplyBrightness;

            imageFilterHandler += filters.ApplyContrast;
            imageFilterHandler += ResizeImage;
            processor.Process("C:/Photos/sample.jpg", imageFilterHandler);
        }
Ejemplo n.º 2
0
        //Other developers won't be able to apply a filter that hasn't been defined
        //To make a new filter, he's going to have to decompile and redeploy the code
        //With delegates a developer create his own filter without relying on this code
        public void ApplyFiltersWithoutDelegate(string path)
        {
            var image = Image.Create(path, "img");

            var filters = new ImageFilters();

            filters.ApplyBrightnessFilter(image);
            filters.ApplyContrastFilter(image);
            filters.ApplyResizeFilter(image);

            image.Save();
        }
Ejemplo n.º 3
0
        static void ClientWithDelegate()
        {
            ImageProcessor imageProcessor = new ImageProcessor();
            ImageFilters   imageFilters   = new ImageFilters();

            ImageProcessor.ImageFilterHandler filterHandler = imageFilters.ApplyBrightnessFilter;

            //To add another filter
            //Those methods must have the same return type as well as the same parameters
            filterHandler += imageFilters.ApplyContrastFilter;

            //Add created filter
            filterHandler += ApplyRedEyeFilter;

            imageProcessor.ApplyFiltersWithDelegate(@"C:\img.jpg", filterHandler);
        }