Esempio n. 1
0
        static void Main(string[] args)
        {
            var chanLoadImage     = new ChannelAgent <string>();
            var chanApply3DEffect = new ChannelAgent <ImageInfo>();
            var chanSaveImage     = new ChannelAgent <ImageInfo>();

            // TODO : 6.7
            // Update the "Subscribe" function in the way that accepts an optional collections of Channels as last arguments.
            // If this argument is present, the output of the channel is broadcast to all the channels
            chanLoadImage.Subscribe(image =>
            {
                var imageInfo = new ImageInfo
                {
                    Path  = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
                    Name  = Path.GetFileName(image),
                    Image = new Bitmap(image)
                };
                chanApply3DEffect.Send(imageInfo);
            });

            chanApply3DEffect.Subscribe(imageInfo =>
            {
                imageInfo.Image = ConvertImageTo3D(imageInfo.Image);
                chanSaveImage.Send(imageInfo);
            });

            // ImageProcessing.ImageHandler.SetGrayscale()
            // ImageProcessing.ImageHandler.SetColorFilter()\
            chanSaveImage.Subscribe(imageInfo =>
            {
                Console.WriteLine($"Saving image {imageInfo.Name}");
                var destination = Path.Combine(imageInfo.Path, imageInfo.Name);
                imageInfo.Image.Save(destination);
            });

            var images = Directory.GetFiles(@".\Images");

            foreach (var image in images)
            {
                chanLoadImage.Send(image);
            }

            Console.ReadLine();
            TaskPool.Stop();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var chanLoadImage     = new ChannelAgent <string>();
            var chanApply3DEffect = new ChannelAgent <ImageInfo>();
            var chanSaveImage     = new ChannelAgent <ImageInfo>();

            chanLoadImage.Subscribe(image =>
            {
                var imageInfo = new ImageInfo
                {
                    Path  = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
                    Name  = Path.GetFileName(image),
                    Image = new Bitmap(image)
                };
                chanApply3DEffect.Send(imageInfo);
            });

            chanApply3DEffect.Subscribe(imageInfo =>
            {
                imageInfo.Image = ConvertImageTo3D(imageInfo.Image);
                chanSaveImage.Send(imageInfo);
            });

            chanSaveImage.Subscribe(imageInfo =>
            {
                Console.WriteLine($"Saving image {imageInfo.Name}");
                var destination = Path.Combine(imageInfo.Path, imageInfo.Name);
                imageInfo.Image.Save(destination);
            });

            var images = Directory.GetFiles(@".\Images");

            foreach (var image in images)
            {
                chanLoadImage.Send(image);
            }

            Console.ReadLine();
            TaskPool.Stop();
        }