Ejemplo n.º 1
0
        public CIImage OutputImage()
        {
            var inputImage = ValueForKey(new NSString("inputImage"));

            if (inputImage == null)
            {
                return(null);
            }

            // Monochrome
            var monochromeFilter = CIFilter.FromName("CIColorMatrix");

            monochromeFilter.SetDefaults();
            monochromeFilter.SetValueForKey(CIVector.Create(0, 0, 0), new NSString("inputRVector"));
            monochromeFilter.SetValueForKey(CIVector.Create(0, 0, 0.4f), new NSString("inputGVector"));
            monochromeFilter.SetValueForKey(CIVector.Create(0, 0, 1), new NSString("inputBVector"));
            monochromeFilter.SetValueForKey(CIVector.Create(0, 0, 1), new NSString("inputAVector"));
            monochromeFilter.SetValueForKey(inputImage, new NSString("inputImage"));
            var glowImage = (CIImage)monochromeFilter.ValueForKey(new NSString("outputImage"));

            // Scale
            var centerX = CenterX;
            var centerY = CenterY;

            if (centerX > 0)
            {
                var transform = new NSAffineTransform();
                transform.Translate(centerX, centerY);
                transform.Scale(1.2f);
                transform.Translate(-centerX, -centerY);

                var affineTransformFilter = CIFilter.FromName("CIAffineTransform");
                affineTransformFilter.SetDefaults();
                affineTransformFilter.SetValueForKey(transform, new NSString("inputTransform"));
                affineTransformFilter.SetValueForKey(glowImage, new NSString("inputImage"));
                glowImage = (CIImage)affineTransformFilter.ValueForKey(new NSString("outputImage"));
            }

            // Blur
            var gaussianBlurFilter = CIFilter.FromName("CIGaussianBlur");

            gaussianBlurFilter.SetDefaults();
            gaussianBlurFilter.SetValueForKey(glowImage, new NSString("inputImage"));
            gaussianBlurFilter.SetValueForKey(InputRadius != null ? InputRadius : new NSNumber(10.0f), new NSString("inputRadius"));
            glowImage = (CIImage)gaussianBlurFilter.ValueForKey(new NSString("outputImage"));

            // Blend
            var blendFilter = CIFilter.FromName("CISourceOverCompositing");

            blendFilter.SetDefaults();
            blendFilter.SetValueForKey(glowImage, new NSString("inputBackgroundImage"));
            blendFilter.SetValueForKey(blendFilter, new NSString("inputImage"));
            glowImage = (CIImage)blendFilter.ValueForKey(new NSString("outputImage"));

            return(glowImage);
        }
Ejemplo n.º 2
0
        private void Pointalize()
        {
            CIVector center = CIVector.Create(Bounds.GetMidX(), Bounds.GetMidY());

            CIFilter pointalize = CIFilter.FromName("CIPointillize");

            pointalize.SetValueForKey(NSNumber.FromFloat(1), CIFilterInputKey.Radius);
            pointalize.SetValueForKey(center, CIFilterInputKey.Center);

            controls.ContentFilters = new CIFilter[] { pointalize };
        }
        void ApplyFilter()
        {
            CIVector center = CIVector.Create(Bounds.GetMidX(), Bounds.GetMidY());
            CIFilter torus  = CIFilter.FromName("CITorusLensDistortion");

            var keys = new NSString[] { CIFilterInputKey.Center,
                                        CIFilterInputKey.Radius,
                                        CIFilterInputKey.Width,
                                        CIFilterInputKey.Refraction };
            var values = new NSObject[] { center,
                                          NSNumber.FromFloat(150),
                                          NSNumber.FromFloat(2),
                                          NSNumber.FromFloat(1.7f) };

            torus.SetValuesForKeysWithDictionary(NSDictionary.FromObjectsAndKeys(values, keys));

            controls.BackgroundFilters = new CIFilter[] { torus };
            AddAnimationToTorusFilter();
        }